Competitive programming questions
رفتن به کانال در Telegram
Solving competitive Programming Questions one day at a time. Group link: https://t.me/competitive_programming_question Please forward it to your friends
نمایش بیشترکشور مشخص نشده استدسته بندی مشخص نشده است
6 861
مشترکین
اطلاعاتی وجود ندارد24 ساعت
اطلاعاتی وجود ندارد7 روز
اطلاعاتی وجود ندارد30 روز
آرشیو پست ها
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. Also update with your answer.
https://www.prodevelopertutorial.com/remove-duplicates-from-sorted-array-ii-in-cpp/
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.
https://www.prodevelopertutorial.com/n-queens-in-cpp/
Difficulty: Hard
Companies Asked: Accolite, Amazon, Visa, MAQ Software, Amdocs, Twitter
Hope you have solved day 55 question. Below is the solution. Please update with your answers in the comment section.
https://www.prodevelopertutorial.com/word-search-in-cpp/
Day 55 Question:
Word Search
Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.
Difficulty: Medium
Additional Details in below link:
https://www.prodevelopertutorial.com/word-search-in-cpp/
Previous days solution:
Day 52 Solution:
https://www.prodevelopertutorial.com/given-an-array-with-n-objects-colored-red-white-or-blue-sort-them-in-place-so-that-objects-of-the-same-color-are-adjacent-with-the-colors-in-the-order-red-white-and-blue-in-cpp/
Day 53 Solution:
https://www.prodevelopertutorial.com/given-two-integers-n-and-k-return-all-possible-combinations-of-k-numbers-out-of-1-n-in-cpp/
Day 54 Solution:
https://www.prodevelopertutorial.com/given-a-set-of-distinct-integers-nums-return-all-possible-subsets-the-power-set-in-cpp/
The group link is the description, please share the group with your friends and post it in other telegram groups, so that it will help others. TIA.
Day 54 Question:
Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
Input: nums = [1,2,3]
Output:
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
]
Difficulty: Medium
Companies Asked: Microsoft, Amazon
Hope you have solved day 51 question. Solution in below link:
https://www.prodevelopertutorial.com/search-a-2d-matrix-in-c/
Please update with your answers in the comment section of the post.
Day 53 Question:
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
Example:
Input: n = 4, k = 2
Output:
[
[2,4],
[3,4],
[2,3],
[1,2],
[1,3],
[1,4],
]
Difficulty: Medium
Day 52 Question:
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
Note: You are not suppose to use the library's sort function for this problem.
More details in below link, update with your answer.
https://www.prodevelopertutorial.com/given-an-array-with-n-objects-colored-red-white-or-blue-sort-them-in-place-so-that-objects-of-the-same-color-are-adjacent-with-the-colors-in-the-order-red-white-and-blue-in-cpp/
Difficulty: Medium
Companies Asked: Paytm, Microsoft, Morgan Stanley, Amazon, Hike, Ola Cabs, Walmart, MAQ Software, Adobe
Day 51 Question:
Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorted from left to right.
The first integer of each row is greater than the last integer of the previous row.
More details in below link, update with your answer.
https://www.prodevelopertutorial.com/search-a-2d-matrix-in-c/
Difficulty: Medium
Companies Asked: Paytm, Accolite, Ola Cabs, Oracle, Visa, MakeMyTrip, Groupon, InMobi, Polycom, TinyOwl
Hope you have solved day 50th question.
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place
Solution in below link:
https://www.prodevelopertutorial.com/given-a-m-x-n-matrix-if-an-element-is-0-set-its-entire-row-and-column-to-0-do-it-in-place-in-cpp/
Please update with your answers in the comment section of the post.
Day 50 Question:
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place
Full Description about the problem in the below link. Also update with your answer.
https://www.prodevelopertutorial.com/given-a-m-x-n-matrix-if-an-element-is-0-set-its-entire-row-and-column-to-0-do-it-in-place-in-cpp/
Difficulty: Medium
Companies Asked: VMWare, Amazon, Ola Cabs, Boomerang Commerce.
Hope you have solved day 49 question.
Jump Game II in CPP
Solution in below link:
https://www.prodevelopertutorial.com/jump-game-ii-in-cpp/
Please update with your answers in the comment section of the post.
Day 49 Question:
Jump Game II in CPP
Full Description about the problem in the below link. Also update with your answer.
https://www.prodevelopertutorial.com/jump-game-ii-in-cpp/
Difficulty: Hard
Companies Asked: Moonfrog Labs, Amazon, Housing.com, Walmart, Adobe
Hope you have solved yesterday's and today's questions, below is the solutions.
Question 47:
Minimum Path Sum in CPP
Solution:
https://www.prodevelopertutorial.com/minimum-path-sum-in-cpp/
Question 48:
Simplify Path CPP
Solution:
https://www.prodevelopertutorial.com/simplify-path-cpp/
Please comment with your answers in the comment section of the above post. Feedbacks are greatly appreciated.
Day 48 Question:
Given an absolute path for a file (Unix-style), simplify it.
For example,
path = "/home/", => "/home"
path = "/a/./b/../../c/", => "/c"
Corner Cases:
Did you consider the case where path = "/../"?
In this case, you should return "/".
Another corner case is the path might contain multiple slashes '/' together, such as "/home//foo/".
In this case, you should ignore redundant slashes and return "/home/foo".
Difficulty: Medium
Day 47 Question:
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.
Example:
Input:
[
[1,3,1],
[1,5,1],
[4,2,1]
]
Output: 7
Explanation: Because the path 1→3→1→1→1 minimizes the sum.
Difficulty: Medium
Companies Asked: Amazon
Hope you have solved today's questions, below is the solutions.
Question:
A robot is located at the top-left corner of a m x n grid.
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid.
Now consider if some obstacles are added to the grids. How many unique paths would there be?
Solution:
https://www.prodevelopertutorial.com/unique-paths-ii-in-c/
Please comment with your answers in the comment section of the above post.
Day 46 Question:
A robot is located at the top-left corner of a m x n grid.
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid.
Now consider if some obstacles are added to the grids. How many unique paths would there be?
An obstacle and empty space is marked as 1 and 0 respectively in the grid.
Note: m and n will be at most 100.
Example 1:
Input:
[
[0,0,0],
[0,1,0],
[0,0,0]
]
Output: 2
Explanation:
There is one obstacle in the middle of the 3x3 grid above.
There are two ways to reach the bottom-right corner:
1. Right -> Right -> Down -> Down
2. Down -> Down -> Right -> Right
Difficulty: Medium
Companies Asked: Paytm, Microsoft, Walmart
Hope you have solved previous questions, below are the solutions. Please update your answers in the appropriate links.
=========================================
Day 39th Question:
Merge Intervals
Solution:
https://www.prodevelopertutorial.com/merge-intervals-in-c/
=========================================
Day 40th Question:
Reverse Linked List iterative and recursive in C++
Solution:
https://www.prodevelopertutorial.com/reverse-linked-list-iterative-and-recursive-in-c/
=========================================
Day 41st Question:
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order in C++
Solution:
https://www.prodevelopertutorial.com/given-a-positive-integer-n-generate-a-square-matrix-filled-with-elements-from-1-to-n2-in-spiral-order-in-c/
=========================================
Day 42nd Question:
Wildcard Matching in C++
Solution:
https://www.prodevelopertutorial.com/wildcard-matching-in-c/
=========================================
Day 43rd Question:
Find Intersection of Two Linked Lists in c++
Solution:
https://www.prodevelopertutorial.com/find-intersection-of-two-linked-lists-in-c/
=========================================
Day 44th Question:
Rotate linked list by k nodes in C++
Solution:
https://www.prodevelopertutorial.com/rotate-linked-list-by-k-nodes-in-c/
=========================================
Day 45th Question:
Unique Paths Solution in C++
Solution:
https://www.prodevelopertutorial.com/unique-paths-solution-in-c/
Day 45 Question:
A robot is located at the top-left corner of a m x n grid .
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid ].
How many possible unique paths are there?
Example 1:
Input: m = 3, n = 2
Output: 3
Explanation:
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
1. Right -> Right -> Down
2. Right -> Down -> Right
3. Down -> Right -> Right
Example 2:
Input: m = 7, n = 3
Output: 28
Difficulty: Medium
Companies Asked: Paytm, Microsoft, Amazon, Walmart
