Competitive programming questions
Kanalga Telegram’da o‘tish
Solving competitive Programming Questions one day at a time. Group link: https://t.me/competitive_programming_question Please forward it to your friends
Ko'proq ko'rsatishMamlakat belgilanmaganToif belgilanmagan
6 861
Obunachilar
Ma'lumot yo'q24 soatlar
Ma'lumot yo'q7 kunlar
Ma'lumot yo'q30 kunlar
Postlar arxiv
Day 28th Question:
Merge k sorted linked lists and return it as one sorted list.
Solution:
https://www.prodevelopertutorial.com/merge-k-sorted-linked-lists-and-return-it-as-one-sorted-list/
=========================================
Day 37th Question:
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
Solution:
https://www.prodevelopertutorial.com/given-a-matrix-of-m-x-n-elements-m-rows-n-columns-return-all-elements-of-the-matrix-in-spiral-order-in-cpp/
=========================================
Day 38th Question:
Given an array of non-negative integers determine if you are able to reach the last index in C++
Solution:
https://www.prodevelopertutorial.com/given-an-array-of-non-negative-integers-determine-if-you-are-able-to-reach-the-last-index-in-c/
Day 44 Question:
Given a linked list, rotate the list to the right by k places, where k is non-negative.
Example 1:
Input: 1->2->3->4->5->NULL, k = 2
Output: 4->5->1->2->3->NULL
Explanation:
rotate 1 steps to the right: 5->1->2->3->4->NULL
rotate 2 steps to the right: 4->5->1->2->3->NULL
Example 2:
Input: 0->1->2->NULL, k = 4
Output: 2->0->1->NULL
Explanation:
rotate 1 steps to the right: 2->0->1->NULL
rotate 2 steps to the right: 1->2->0->NULL
rotate 3 steps to the right: 0->1->2->NULL
rotate 4 steps to the right: 2->0->1->NULL
Difficulty: Medium
Hope you have solved previous questions, below are the solutions
Day 32nd Question:
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
Solution:
https://www.prodevelopertutorial.com/given-a-collection-of-distinct-integers-return-all-possible-permutations-2/
=========================================
Day 33rd Question:
Given an n x n 2D matrix rotate it by 90 degrees (clockwise) in C++ in place
Solution:
https://www.prodevelopertutorial.com/given-an-n-x-n-2d-matrix-rotate-it-by-90-degrees-clockwise-in-c-in-place/
=========================================
Day 34th Question:
Group Anagrams in C++
Solution:
https://www.prodevelopertutorial.com/group-anagrams-in-c/
=========================================
Day 35th Question:
Rain water trapping in C++
Solution:
https://www.prodevelopertutorial.com/rain-water-trapping-in-c/
=========================================
Day 36th Question:
Implement pow(x, n), which calculates x raised to the power n (xn) in C++
Solution:
https://www.prodevelopertutorial.com/implement-powx-n-which-calculates-x-raised-to-the-power-n-xn-in-c/
Day 43 Question:
Write a program to find the node at which the intersection of two singly linked lists Sorted and Unsorted.
For example, the following two linked lists:
A: a1 → a2
↘️
c1 → c2 → c3
↗️
B: b1 → b2 → b3
begin to intersect at node c1.
Notes:
If the two linked lists have no intersection at all, return null.
The linked lists must retain their original structure after the function returns.
You may assume there are no cycles anywhere in the entire linked structure.
Your code should preferably run in O(n) time and use only O(1) memory.
Difficulty: Easy
Companies Asked: Accolite, Microsoft, Amazon, D-E-Shaw, Goldman Sachs, MakeMyTrip, Qualcomm, Zopper
Day 42 Question:
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.
'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lowercase letters a-z.
p could be empty and contains only lowercase letters a-z, and characters like ? or *.
Example 1:
Input:
s = "aa"
p = "a"
Output: false
Explanation: "a" does not match the entire string "aa".
Example 2:
Input:
s = "aa"
p = "*"
Output: true
Explanation: '*' matches any sequence.
Example 3:
Input:
s = "cb"
p = "?a"
Output: false
Explanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.
Example 4:
Input:
s = "adceb"
p = "*a*b"
Output: true
Explanation: The first '*' matches the empty sequence, while the second '*' matches the substring "dce".
Example 5:
Input:
s = "acdcb"
p = "a*c?b"
Output: false
Difficulty: Hard
Companies Asked: Microsoft, Amazon, Ola Cabs, Walmart, InMobi, United Health Group
Day 41 Question:
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
]
Difficulty: Medium
Companies Asked: Microsoft JP Morgan Amazon
Day 40 Question:
Reverse Linked List
Reverse a singly linked list.
Example:
Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL
Follow up:
A linked list can be reversed either iteratively or recursively. Could you implement both?
Difficulty: Easy
Quote:
Be like a duck, paddling and working hard in the water, but what everyone sees is a smiling, calm face.
Day 39 Question:
Given a collection of intervals, merge all overlapping intervals.
Example 1:
Input: [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].
Example 2:
Input: [[1,4],[4,5]]
Output: [[1,5]]
Explanation: Intervals [1,4] and [4,5] are considerred overlapping.
Difficulty: Medium
Company asked: Google, Amazon
Day 31st Question:
Given a collection of distinct integers, return all possible permutations.
Solution:
https://www.prodevelopertutorial.com/given-a-collection-of-distinct-integers-return-all-possible-permutations/
Please comment with your answers in the comment section of the above post.
Day 38 Question:
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Determine if you are able to reach the last index.
Example 1:
Input: [2,3,1,1,4]
Output: true
Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.
Example 2:
Input: [3,2,1,0,4]
Output: false
Explanation: You will always arrive at index 3 no matter what. Its maximum
jump length is 0, which makes it impossible to reach the last index.
Difficulty: Medium
Company asked: Moonfrog Labs, Amazon, Housing.com, Walmart
Quote:
The difference between ordinary and extraordinary is that little extra
Day 37 Question:
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
Example 1:
Input:
[
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
]
Output: [1,2,3,6,9,8,7,4,5]
Example 2:
Input:
[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9,10,11,12]
]
Output: [1,2,3,4,8,12,11,10,9,5,6,7]
Difficulty: Medium
Company asked: Paytm, Microsoft, Morgan Stanley, D-E-Shaw, Oracle, Snapdeal, MAQ Software, MakeMyTrip
Quote:
There is no substitute for hard work.
Day 36 Question:
Implement pow(x, n), which calculates x raised to the power n (xn).
Example 1:
Input: 2.00000, 10
Output: 1024.00000
Example 2:
Input: 2.10000, 3
Output: 9.26100
Example 3:
Input: 2.00000, -2
Output: 0.25000
Explanation: 2-2 = 1/22 = 1/4 = 0.25
Note:
-100.0 < x < 100.0
n is a 32-bit signed integer, within the range [−231, 231 − 1]
Difficulty: Medium
Companies Asked: Microsoft MakeMyTrip
Quote:
Opportunities are usually disguised as hard work, so most people don't recognize them.
Day 35 Question:
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
Examples:
Input: arr[] = {2, 0, 2}
Output: 2
Structure is like below
| |
|_|
We can trap 2 units of water in the middle gap.
Input: arr[] = {3, 0, 0, 2, 0, 4}
Output: 10
Structure is like below
|
| |
| | |
|__|_|
We can trap "3*2 units" of water between 3 an 2,
"1 unit" on top of bar 2 and "3 units" between 2
and 4. See below diagram also.
Input: arr[] = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]
Output: 6
|
| || |
_|_||_||||||
Trap "1 unit" between first 1 and 2, "4 units" between
first 2 and 3 and "1 unit" between second last 1 and last 2
Difficulty: HARD
Companies Asked: Accolite Microsoft Amazon D-E-Shaw Payu Adobe
Try with below Constraints:
Time Complexity: O(n)
Auxiliary Space: O(n)
Motivational quote for the day:
Once you have commitment, you need the discipline and hard work to get you there.
If you feel that I have helped you to improve your programming skill, I request you to please give a 5 star rating in below link.
https://tchannels.me/c/competitive_programming_question
Day 34 Question:
Group Anagrams
Given an array of strings, group anagrams together.
Example:
Input: ["eat", "tea", "tan", "ate", "nat", "bat"],
Output:
[
["ate","eat","tea"],
["nat","tan"],
["bat"]
]
Note:
All inputs will be in lowercase.
The order of your output does not matter.
Difficulty: Medium
Asked in companies: Amazon Microsoft
Motivational quote for the day:
There is no substitute for hard work. Never give up. Never stop believing. Never stop fighting.
Note:
I am aware that I am not providing solutions daily EOD as told, as I am facing some technical difficulties. Hopefully it will be resolved by Sunday.
Sorry, below is the correct Day 30th solution link:
https://www.prodevelopertutorial.com/given-two-non-negative-integers-num1-and-num2-represented-as-strings-return-the-product-of-num1-and-num2-also-represented-as-a-string/
Day 33 Question:
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Note:
You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
Example 1:
Given input matrix =
[
[1,2,3],
[4,5,6],
[7,8,9]
],
rotate the input matrix in-place such that it becomes:
[
[7,4,1],
[8,5,2],
[9,6,3]
]
Difficulty: Medium
Companies asked: Google Facebook Amazon
================================================================================
Hope you have solved Day 30th question.
Day 30th Question:
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.
Solution:
https://www.prodevelopertutorial.com/given-a-collection-of-distinct-integers-return-all-possible-permutations/
Please comment with your answers in the comment section of the above post.
Companies asked: Microsoft Flipkart Adobe Facebook
Hope you have solved Day 29th question.
Day 29th Question:
Given a collection of candidate numbers and a key, find all unique combinations in candidates where the candidate numbers sums to target
Solution:
https://www.prodevelopertutorial.com/given-a-collection-of-candidate-numbers-and-a-key-find-all-unique-combinations-in-candidates-where-the-candidate-numbers-sums-to-target/
Please comment with your answers in the comment section of the above post.
Day 32 Question:
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
Example:
Input: [1,1,2]
Output:
[
[1,1,2],
[1,2,1],
[2,1,1]
]
Difficulty: Medium
Companies asked: Microsoft Facebook Google
Hope you have solved Day 27th question.
Day 27 Question:
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).
You are given a target value to search. If found in the array return its index, otherwise return -1.
You may assume no duplicate exists in the array.
Your algorithm's runtime complexity must be in the order of O(log n).
Solution:
https://www.prodevelopertutorial.com/given-an-array-sorted-in-ascending-order-and-is-rotated-at-some-pivot-given-a-target-value-to-search-if-found-in-the-array-return-its-index/
Please comment with your answers in the comment section of the above post.
