Competitive Programming
رفتن به کانال در Telegram
Solving competitive Programming Questions one day at a time. Group link: https://t.me/daily1interviewprogram Please forward it to your friends
نمایش بیشترکشور مشخص نشده استدسته بندی مشخص نشده است
4 553
مشترکین
اطلاعاتی وجود ندارد24 ساعت
اطلاعاتی وجود ندارد7 روز
اطلاعاتی وجود ندارد30 روز
آرشیو پست ها
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/
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
