es
Feedback
Competitive programming questions

Competitive programming questions

Ir al canal en Telegram

Solving competitive Programming Questions one day at a time. Group link: https://t.me/competitive_programming_question Please forward it to your friends

Mostrar más
El país no está especificadoLa categoría no está especificada
6 861
Suscriptores
Sin datos24 horas
Sin datos7 días
Sin datos30 días
Archivo de publicaciones
Day 60 Question: Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. Example: Input: head = 1->4->3->2->5->2, x = 3 Output: 1->2->2->4->3->5 Difficulty: Medium Update with your answers in the comment section of the link below: http://bit.ly/q_60 ============================= Linux command for the day: ============================= Linux rmdir Name: Remove “empty” Directory in Linux. Options: -v Display message after operation is completed. -p Removes parent directory also. --ignore-fail-on-non-empty Will not display the error message, if the command is not able to delete the directory because it is not empty. Example: 1. Remove simple directory. “rm test_dir” 2. Remove directory with exit message. “rm –v test_dir” 3. Remove directory along with parent directory. “rm –p dir_1/dir_2/dir_3” 4. Remove directory by supressing the warnings. “rm --ignore-fail-on-non-empty dir_1”

Day 59 Question: Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example 1: Input: 1->2->3->3->4->4->5 Output: 1->2->5 Example 2: Input: 1->1->1->2->3 Output: 2->3 Difficulty: Medium Update with your answers in the comment section of the link below: http://bit.ly/q_59 ============================= Linux command for the day: ============================= Linux mkdir Name: Create Linux directory Options: -v Write message after every operation -p Create parent directory if needed -m To specify the permissions Example: 1. Create a simple directory. “mkdir test_dir” 2. Create directory with message after operation is completed “mkdir –v test_dir” 3. Create directory with parent directory. “mkdir –p dir_1/dir_2/dir_3” 4. Create directory with permissions. “mkdir –m 777 test_dir”

Hope you have solved Day 58 question. Click the below link to get the solution. http://bit.ly/q_58

Day 58 Question: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]). You are given a target value to search. If found in the array return true, otherwise return false. Example 1: Input: nums = [2,5,6,0,0,1,2], target = 0 Output: true Example 2: Input: nums = [2,5,6,0,0,1,2], target = 3 Output: false Difficulty: Medium More details in the below link. Also update with your answer. http://bit.ly/q_58 ============================= Linux command for the day: ============================= Linux Absolute and Relative paths Linux Absolute path: If the path to a particular directory starts from root directory is called as absolute path. Example: cd /usr/local/sbin Linux Relative Path: If the path to a directory starts by taking the present directory as a reference, then it is called as relative path. Example: You are in “/usr/local/sbin” and you want to navigate to “/usr/local/”: Using Absolute path, you write “cd /usr/local/”. Using Relative path, you write “cd ../”.

Solution to day 57 problem: http://bit.ly/q_57

Day 57 Question: Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Difficulty: Medium Companies Asked: Morgan Stanley, Xome More details in the below link. Update your queries and answers in the comment section of the post below: http://bit.ly/q_57 ============================= Linux command for the day: ============================= Linux cd: Usage: “cd” stands for Change Directory. Change Directory is one of the basic commands to be known. When you are working on a terminal, “cd” is the only command that you can use to navigate from one directory to another. Below we shall see some of the variants of “cd” command. Options: -L: Follow the symbolic link. -P: Resolve the symbolic link, go to the actual directory. Examples: 1. To go to “/usr/local/” directory from present directory: cd /usr/local 2. To go to the previous directory from where you were working: cd – 3. To go to one level up from the present directory use “..” cd .. 4. To go to home directory use “cd “

Solution to Day 56 problem: http://bit.ly/q_56 Update with your answers

Day 56 Question: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. More details in the below link. Also update with your answer. http://bit.ly/q_56 Difficulty: Hard Companies Asked: Accolite, Amazon, Visa, MAQ Software, Amdocs, Twitter Linux command for the day: ============================= Linux pwd Name: Print Working Directory Description: This command is used to print the path of present working directory. It will show the path starting from the “root” directory. Options: -L – Print the logical directory path, even if it is a symbolic link. This will be the default option, if no options are mentioned. -P – If the directory is a symbolic link, then resolve that link and print the resolved path.

Hi Dear Members, as communicated we shall resume our competitive programming journey from monday starting from Question No 56.

Hello Dear Members, I have not been active from past 3 days. I am preparing questions to be posted. Hence shall resume the question and answer from next week for sure if not early. I am sorry for the delay.

Day 67 Question: Insert Interval Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example 1: Input: intervals = [[1,3],[6,9]], newInterval = [2,5] Output: [[1,5],[6,9]] Example 2: Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8] Output: [[1,2],[3,10],[12,16]] Explanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10]. Difficulty: Hard

Day 66 Question: Restore IP Addresses Given a string containing only digits, restore it by returning all possible valid IP address combinations. Example: Input: "25525511135" Output: ["255.255.11.135", "255.255.111.35"] Difficulty: Medium

Day 65 Question: Reverse Linked List II Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: Input: 1->2->3->4->5->NULL, m = 2, n = 4 Output: 1->4->3->2->5->NULL Difficulty: Medium

Day 64 Question: Decode Ways A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given a non-empty string containing only digits, determine the total number of ways to decode it. Example 1: Input: "12" Output: 2 Explanation: It could be decoded as "AB" (1 2) or "L" (12). Example 2: Input: "226" Output: 3 Explanation: It could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6). Difficulty: Medium Companies Asked: Facebook Amazon

Day 63 Question: Valid Number Validate if a given string is numeric. Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true Difficulty: Hard

Day 62 Question: Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. Example: Input: [1,2,2] Output: [ [2], [1], [1,2,2], [2,2], [1,2], [] ] Difficulty: Medium

Day 61 Question: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Example 1: Input: 2 Output: [0,1,3,2] Explanation: 00 - 0 01 - 1 11 - 3 10 - 2 For a given n, a gray code sequence may not be uniquely defined. For example, [0,2,3,1] is also a valid gray code sequence. 00 - 0 10 - 2 11 - 3 01 - 1 Example 2: Input: 0 Output: [0] Explanation: We define the gray code sequence to begin with 0. A gray code sequence of n has size = 2n, which for n = 0 the size is 20 = 1. Therefore, for n = 0 the gray code sequence is [0]. Difficulty: Medium

Day 60 Question: Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. Example: Input: head = 1->4->3->2->5->2, x = 3 Output: 1->2->2->4->3->5 Difficulty: Medium Note: Solutions to previous questions will be provided shortly. If you have completed the solutions, request you to please update in appropriate post in the comments section.

Day 59 Question: Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example 1: Input: 1->2->3->3->4->4->5 Output: 1->2->5 Example 2: Input: 1->1->1->2->3 Output: 2->3 Difficulty: Medium Solutions to previous questions will be provided soon.

Day 58 Question: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]). You are given a target value to search. If found in the array return true, otherwise return false. Example 1: Input: nums = [2,5,6,0,0,1,2], target = 0 Output: true Example 2: Input: nums = [2,5,6,0,0,1,2], target = 3 Output: false Difficulty: Medium More details in the below link. Also update with your answer. https://www.prodevelopertutorial.com/search-in-rotated-sorted-array-ii-in-cpp/