├── Walmart ├── Links here.txt ├── 2. Stone Game.cpp ├── 5. Find the Kth Largest Integer in the Array.cpp ├── 7. Remove Colored Pieces if Both Neighbors are the Same Color.cpp ├── 11. Guess Number Higher or Lower II.cpp ├── 6. Divide Two Integers.cpp ├── 4. Maximum Height Tree.cpp ├── 13. Maximum Performance of a Team.cpp ├── 12. Generate Random Point in a Circle.cpp ├── 8. Numbers of unique Path .cpp ├── 15. Find Array Given Subset Sums.cpp ├── 14. Path with Maximum Probability.cpp ├── 1. Power Of Numbers.cpp ├── 3. Largest number in K swaps.cpp ├── 10. Shortest subsequence of size 3 .cpp └── 9. Transform to Sum Tree .cpp ├── Goldman Sachs ├── _6_GreatestCommonDivisorOfStrings.cpp ├── _14_MinimumSizeSubarraySum.cpp ├── _7_FindThePositionOfMthItem.cpp ├── _12_SquaresInChessboard.cpp ├── _4_RunLengthEncoding.cpp ├── _2_OverlappingRectangles.cpp ├── _10_Max10Numbers.cpp ├── _9_NumberFollowingAPattern.cpp ├── _8_TotalDecodingMessages.cpp ├── _13_DecodeTheString.cpp ├── _3_SubarraysHavingProductLessThanK.cpp ├── _1_PrintAnagramsTogether.cpp ├── _15_ArrayPairSumDivisibilityProblem.cpp ├── _5_UglyNumbers.cpp └── _11_FindMissingAndRepeating.cpp ├── Adobe ├── Amend The Sentence .cpp ├── Express as sum of power of natural numbers.cpp ├── Most_recent Library.cpp ├── Question Link here ├── Implement_atoi.cpp ├── Minimum operations to convert array A to B .cpp ├── Generate Parentheses. cpp ├── partition Equal Subset Sum .cpp ├── Number of distict Words with k maximum contiguous vowels .cpp ├── leaders in an array.cpp ├── Longest Arithmetic Progression .cpp ├── Pots of Gold game .cpp ├── Winner of a election.cpp ├── Subarray with given sum.cpp ├── Smallest range in K lists.cpp └── Next higher palindromic number using the same set of digits .cpp ├── Intuit ├── 1.koko_eating_banana.cpp ├── 12. numbers of provinces .cpp ├── 11. Number of Boomerangs.cpp ├── 3.Course_Schedule.cpp ├── 7. Capacity To Ship Packages Within D Days.cpp ├── 6.Split Array Largest Sum.cpp ├── Question Links here.txt ├── 2. Minimum sum partition.cpp ├── 14. Minimum Swaps to Arrange a Binary Grid.cpp ├── 9.Maximum number in K swaps .cpp ├── 13. As Far from Land as Possible .cpp ├── 15. Pacific Atlantic Water Flow.cpp ├── 8. Find in the mountain array .cpp ├── 10. Construct Quad Tree.cpp ├── 5.find the missing no in the string .cpp └── 4. Word search .cpp ├── Amazon ├── Count ways to N'th Stair(Order does not matter).cpp ├── Column name from a given column number.cpp ├── Longest Mountain in Array.cpp ├── rotten-oranges.cpp ├── Maximum_Profit.cpp ├── First non-repeating character in a stream.cpp ├── IPL 2021 - Match Day 2 .cpp ├── Is-Sudoku-Valid.cpp ├── Maximum of all subarrays of size k.cpp ├── Brackets in Matrix Chain Multiplication.cpp ├── Nuts and Bolts Problem.cpp ├── Delete N nodes after M nodes of a linked list.cpp ├── Burning_tree.cpp ├── Phone directory.cpp └── Serialize and Deserialize a Binary Tree.cpp ├── Microsoft ├── Generate Binary Numbers.cpp ├── Minimum steps to destination.cpp ├── Stickler_Thief .cpp ├── Stock_span.cpp ├── minimum_sum_partition.cpp ├── Rotate_by_90-degree.cpp ├── Bridge edge in a graph.cpp ├── Unit Area of largest region of 1's.cpp ├── Possible Words From Phone Digits.cpp ├── Find All Four Sum Numbers.cpp ├── Prerequisite_Tasks.cpp ├── Spirally traversing a matrix.cpp ├── Alien Dictionary.cpp ├── Count Number of SubTrees having given Sum.cpp └── Connect Nodes at Same Level.cpp ├── assets ├── lc.svg └── gfg.svg ├── TEMPLATE.md └── README.md /Walmart/Links here.txt: -------------------------------------------------------------------------------- 1 | https://docs.google.com/document/d/1XsyXdufDAK1C6PbC0KNeO95ydbH8qlsGnkyThkS-1bs/edit 2 | -------------------------------------------------------------------------------- /Goldman Sachs/_6_GreatestCommonDivisorOfStrings.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string gcdOfStrings(string a, string b) 4 | { 5 | return (a + b== b + a) ? a.substr(0, gcd(a.length(), b.length())): ""; 6 | } 7 | }; -------------------------------------------------------------------------------- /Walmart/2. Stone Game.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool stoneGame(vector& piles) { 4 | int odd_sum =0 ; 5 | int even_sum =0 ; 6 | int n = piles.size() ; 7 | for(int i=0;i& nums, int k) { 4 | int n = nums.size() ; 5 | sort(nums.begin(),nums.end(),cmp) ; 6 | return nums[n-k] ; 7 | } 8 | 9 | static bool cmp(string x , string y) { 10 | int X = x.size() ; 11 | int Y = y.size() ; 12 | if(X==Y) 13 | return x& A) 6 | { 7 | int i = 0, n = A.size() ,summation = n + 1; 8 | for (int j = 0; j < n; ++j) 9 | { 10 | s -= A[j]; 11 | while (s <= 0) 12 | { 13 | summation = min(summation ,j - i + 1); 14 | s += A[i++]; 15 | } 16 | } 17 | return summation % (n + 1); 18 | } 19 | }; -------------------------------------------------------------------------------- /Walmart/7. Remove Colored Pieces if Both Neighbors are the Same Color.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool winnerOfGame(string colors) { 4 | int n = colors.size() ; 5 | int ascore = 0 ; 6 | int bscore =0 ; 7 | for(int i=1;i<=n-2 ; i++) 8 | { 9 | if(colors[i] =='A' and colors[i] ==colors[i+1] and colors[i] ==colors[i-1]) 10 | ascore ++ ; 11 | else if(colors[i] =='B' and colors[i] ==colors[i+1] and colors[i] ==colors[i-1]) 12 | bscore ++ ; 13 | } 14 | 15 | return (ascore > bscore) ; 16 | } 17 | }; -------------------------------------------------------------------------------- /Adobe/Amend The Sentence .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | 7 | 8 | class Solution{ 9 | public: 10 | string amendSentence (string s) 11 | { 12 | string a = "" ; 13 | a += tolower(s[0]) ; 14 | int i=1 ; 15 | while( s[i] != '\0') { 16 | if(isupper(s[i])) a += " " ; 17 | a += tolower(s[i]) ; 18 | i++ ; 19 | } 20 | return a ; 21 | } 22 | }; 23 | 24 | // { Driver Code Starts. 25 | int main() 26 | { 27 | int t; cin >> t; 28 | while (t--) 29 | { 30 | string s; cin >> s; 31 | Solution ob; 32 | cout << ob.amendSentence (s) << endl; 33 | } 34 | } // } Driver Code Ends 35 | -------------------------------------------------------------------------------- /Walmart/11. Guess Number Higher or Lower II.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int dp[201][201] ; 4 | 5 | int f(int i,int j) 6 | { 7 | if(i>=j){ 8 | return 0 ; 9 | } 10 | if(dp[i][j]!= -1) 11 | return dp[i][j] ; 12 | 13 | int ans = 100000; 14 | 15 | for(int k= i ; k<=j ; k++) 16 | { 17 | int cost = max(k+f(i,k-1) , k+ f(k+1,j)) ; 18 | ans = min(ans,cost) ; 19 | } 20 | return dp[i][j] = ans ; 21 | 22 | } 23 | 24 | 25 | int getMoneyAmount(int n) 26 | { 27 | memset(dp,-1,sizeof dp) ; 28 | 29 | return f(1,n) ; 30 | } 31 | }; -------------------------------------------------------------------------------- /Walmart/6. Divide Two Integers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int divide(int x, int y) 4 | { 5 | if (x == INT_MIN && y == -1) { 6 | return INT_MAX; 7 | } 8 | 9 | long dvd = labs(x) ; 10 | long dvs = labs(y) ; 11 | long ans = 0; 12 | long sign = (x > 0) ^ (y > 0) ? -1 : 1; 13 | 14 | while (dvd >= dvs) 15 | { 16 | long temp = dvs ; 17 | long m = 1; 18 | while (temp << 1 <= dvd) 19 | { 20 | temp <<= 1; 21 | m <<= 1; 22 | } 23 | 24 | dvd -= temp; 25 | ans += m; 26 | } 27 | return sign * ans; 28 | } 29 | }; -------------------------------------------------------------------------------- /Adobe/Express as sum of power of natural numbers.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | long long int dp[1001][1001]; 4 | long long int dfs(int n,int x,int i,int j) 5 | { 6 | if(n==0) 7 | return 1; 8 | if(i>j) 9 | return 0; 10 | if(dp[n][i]!=-1) 11 | return dp[n][i]; 12 | long long int temp=pow(i,x); 13 | if(temp<=n) 14 | { 15 | return dp[n][i]=dfs(n-temp,x,i+1,j) + dfs(n,x,i+1,j); 16 | } 17 | else 18 | { 19 | return dp[n][i]= 0; 20 | } 21 | 22 | } 23 | long long int numOfWays(int n, int x) 24 | { 25 | // code here 26 | memset(dp,-1,sizeof dp); 27 | return dfs(n,x,1,n); 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /Goldman Sachs/_7_FindThePositionOfMthItem.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | 3 | #include 4 | using namespace std; 5 | 6 | // } Driver Code Ends 7 | 8 | 9 | class Solution { 10 | public: 11 | int findPosition(int N , int M , int K) { 12 | if(N==1) 13 | return 1 ; 14 | 15 | int choose = M+K-1 ; 16 | if(choose % N ==0) { 17 | return N ; 18 | } 19 | 20 | return choose % N ; 21 | } 22 | }; 23 | 24 | // { Driver Code Starts. 25 | int main() { 26 | int t; 27 | cin >> t; 28 | while (t--) { 29 | int N,M,K; 30 | 31 | cin>>N>>M>>K; 32 | 33 | Solution ob; 34 | cout << ob.findPosition(N,M,K) << endl; 35 | } 36 | return 0; 37 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Intuit/1.koko_eating_banana.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | 4 | // BINARY SEARCH APPLICATION HERE IT IS 5 | 6 | bool possible(int mid , vector & piles , int H) { 7 | int total =0 ; 8 | int n = piles.size() ; 9 | for(int i=0; i< n ; i++) { 10 | int x = piles[i]/mid ; 11 | int y =piles[i] % mid ; 12 | if(y) { x ++ ; } 13 | total += x ; 14 | 15 | } 16 | 17 | return (total <=H) ; 18 | } 19 | 20 | int minEatingSpeed(vector& piles, int H) { 21 | int l = 1 ; 22 | int r = (int)(1e9+1) ; 23 | while(l 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | //User function Template for C++ 9 | 10 | class Solution{ 11 | public: 12 | int height(int N){ 13 | int i =0 ; 14 | 15 | 16 | for( i=0 ; i< 1000 ; i++) 17 | { 18 | int val = (i*(i+1))/2 ; 19 | if(val > N) 20 | break ; 21 | } 22 | 23 | return i-1 ; 24 | } 25 | }; 26 | 27 | // { Driver Code Starts. 28 | 29 | int main(){ 30 | int t; 31 | cin>>t; 32 | while(t--){ 33 | int N; 34 | cin>>N; 35 | 36 | Solution ob; 37 | cout< 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution 7 | { 8 | public: 9 | //Function to count number of ways to reach the nth stair 10 | //when order does not matter. 11 | long long countWays(int m) 12 | { 13 | // your code here 14 | return (long long) (m/2+1) ; 15 | } 16 | }; 17 | 18 | // { Driver Code Starts. 19 | int main() 20 | { 21 | //taking count of testcases 22 | int t; 23 | cin >> t; 24 | 25 | while(t--) 26 | { 27 | //taking stair count 28 | int m; 29 | cin>>m; 30 | Solution ob; 31 | cout< 4 | using namespace std; 5 | 6 | // } Driver Code Ends 7 | 8 | class Solution { 9 | public: 10 | long long squaresInChessBoard(long long N) { 11 | // Number of 1*1 squares = n*n 12 | // Number of 2*2 squares = (n-1)*(n-1) 13 | // ... 14 | // Number of n*n squares = 1*! 15 | // Total squares = Summation of(1*1+2*2+ ... +n*n) 16 | 17 | return N * (N + 1) * (2*N + 1) / 6 ; 18 | 19 | } 20 | }; 21 | 22 | // { Driver Code Starts. 23 | int main() { 24 | int t; 25 | cin >> t; 26 | while (t--) { 27 | long long N; 28 | 29 | cin>>N; 30 | 31 | Solution ob; 32 | cout << ob.squaresInChessBoard(N) << endl; 33 | } 34 | return 0; 35 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Amazon/Column name from a given column number.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | 7 | 8 | class Solution{ 9 | public: 10 | string colName (long long int n) 11 | { 12 | // Simple O(Log26(N)) solution 13 | string ans ; 14 | while(n>0) { 15 | // to make the number 0 ondexed now 16 | n-- ; 17 | int lastdig = n % 26 ; 18 | ans = string(1, lastdig + 'A') + ans ; 19 | n = n/26 ; 20 | } 21 | 22 | 23 | return ans ; 24 | } 25 | }; 26 | 27 | // { Driver Code Starts. 28 | int main() 29 | { 30 | int t; cin >> t; 31 | while (t--) 32 | { 33 | long long int n; cin >> n; 34 | Solution ob; 35 | cout << ob.colName (n) << '\n'; 36 | } 37 | } 38 | // } Driver Code Ends -------------------------------------------------------------------------------- /Intuit/12. numbers of provinces .cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | 4 | 5 | void dfs(vector> & graph , int i) 6 | { 7 | graph[i][i] =0 ; 8 | for(int j=0 ; j>& graph) { 22 | // connected components in the graph 23 | int n = graph.size() ; 24 | int cnt =0 ; 25 | for(int i=0 ; i< n ; i++) { 26 | if(graph[i][i]==0) continue ; 27 | cnt ++ ; 28 | dfs(graph,i) ; 29 | } 30 | return cnt ; 31 | } 32 | }; -------------------------------------------------------------------------------- /Goldman Sachs/_4_RunLengthEncoding.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | string encode(string src); 6 | 7 | int main() { 8 | 9 | int T; 10 | cin>>T; 11 | while(T--) 12 | { 13 | string str; 14 | cin>>str; 15 | 16 | cout<>& p) 4 | { 5 | map f ; 6 | int ans = 0; 7 | int n = p.size() ; 8 | for(int i=0; i 3 | using namespace std; 4 | 5 | 6 | 7 | // } Driver Code Ends 8 | 9 | //Function to generate binary numbers from 1 to N using a queue. 10 | vector generate(int N) 11 | { 12 | 13 | /// using queue data structure ; 14 | vector res ; 15 | 16 | queue q ; 17 | 18 | q.push("1") ; 19 | 20 | for(int i=0;i>t; 38 | while(t--) 39 | { 40 | int n; 41 | cin>>n; 42 | vector ans = generate(n); 43 | for(auto it:ans) cout< 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | // User function Template for C++ 9 | 10 | class Solution { 11 | public: 12 | int doOverlap(int L1[], int R1[], int L2[], int R2[]) { 13 | // code here 14 | 15 | if(L1[0] > R2[0] || L2[0] > R1[0]) return false ; 16 | 17 | if(L1[1] > t; 28 | while (t--) { 29 | int p[2], q[2], r[2], s[2]; 30 | cin >> p[0] >> p[1] >> q[0] >> q[1] >> r[0] >> r[1] >> s[0] >> s[1]; 31 | Solution ob; 32 | int ans = ob.doOverlap(p, q, r, s); 33 | cout << ans << "\n"; 34 | } 35 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Amazon/Longest Mountain in Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestMountain(vector& arr) { 4 | int n = arr.size() ; 5 | // peak dekh lo 6 | int ans =0 ; 7 | for(int i=1 ; i< n-1 ;) 8 | { 9 | if(arr[i] > arr[i-1] && arr[i] > arr[i+1]) // to check for peak element 10 | { 11 | int cnt =1 ; 12 | int j=i ; 13 | // peak to one valley 14 | while(j>0 and arr[j] > arr[j-1]) 15 | { 16 | j-- ; cnt ++ ; 17 | } 18 | 19 | // peak to another valley 20 | while(i < n-1 and arr[i] > arr[i+1]) 21 | { 22 | i++ ; cnt ++ ; 23 | } 24 | ans = max(cnt ,ans) ; // to compute the max len of mountain 25 | } 26 | else{ 27 | i++ ; // if not peak then incre i otherwise not 28 | } 29 | } 30 | return ans ; 31 | } 32 | }; -------------------------------------------------------------------------------- /Adobe/Most_recent Library.cpp: -------------------------------------------------------------------------------- 1 | //Given two library versions of an executable: for example, "10.1.1.3" and "10.1.1.9" or "10" and "10.1". Find out which one is more recent? Strings can be empty also. 2 | 3 | 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int n; 10 | cin >> n; 11 | 12 | vector> arr(n); 13 | 14 | for (int i = 0; i < n; ++i) 15 | { 16 | string version; 17 | cin >> version; 18 | V[i].push_back(0); 19 | for(char c: version) 20 | { 21 | if(c == '.') 22 | arr[i].push_back(0); 23 | else 24 | arr[i].back() = arr[i].back()*10 + (c-48) ; 25 | } 26 | } 27 | 28 | sort(arr.begin(), arr.end()); 29 | 30 | bool dot = false; 31 | 32 | for(auto n: arr.back()) 33 | { 34 | if(dot) cout << "."; 35 | cout << n; 36 | dot = true; 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Walmart/13. Maximum Performance of a Team.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | #define pii pair 4 | int maxPerformance(int n, vector& speed, vector& efficiency, int k) { 5 | vector v ; 6 | 7 | for(int i=0;i, greater> pq ; 14 | long ans = 0 ; 15 | long sum = 0 ; 16 | 17 | for(int i=n-1 ; i>=0 ; i--) 18 | { 19 | sum += v[i].second ; 20 | pq.push(v[i].second) ; 21 | 22 | if(pq.size()>k) 23 | { 24 | sum = sum - pq.top() ; 25 | pq.pop() ; 26 | } 27 | ans = max(ans, sum * v[i].first) ; 28 | } 29 | 30 | 31 | 32 | return ans % 1000000007 ; 33 | } 34 | }; -------------------------------------------------------------------------------- /Adobe/Question Link here: -------------------------------------------------------------------------------- 1 | https://docs.google.com/document/d/1cEAe63fC3YMJRwKmCoVOIXFUaFv5LqNXedxaGpaqd6U/edit 2 | 3 | Arsh Adobe Sheet : 4 | 5 | 1.Find a continuous sub-array which adds to a given number S. 6 | 2.Find the length of the Longest Arithmetic Progression (LLAP) in it. 7 | 3.Number of distinct Words with k maximum contiguous vowels(Joe and his Dictionary Problem) 8 | 4.Partition Equal Subset Sum 9 | 5.Total number of ways n can be expressed as sum of xth power of unique natural numbers 10 | 6.Generate all combinations of well-formed(balanced) parentheses. 11 | 7.Pots of Gold Game (Similar to Covid and Beds problem) 12 | 8.ATOI 13 | 9. Smallest palindromic number greater than N using the same set of digits as in N. 14 | 10.Elections 15 | 11.String Amendment 16 | 12.Leaders in Array 17 | 13.Minimum operations to convert array A to B 18 | 14.Smallest range in K lists 19 | 15.Given two library versions of an executable: for example, “10.1.1.3” and “10.1.1.9” or “10” and “10.1”. Find out which one is more recent? Strings can be empty also. 20 | -------------------------------------------------------------------------------- /Amazon/rotten-oranges.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int orangesRotting(vector& grid) { 4 | if(grid.empty()) 5 | return 0; 6 | int m = grid.size(),n=grid[0].size(),day=0,tot=0,cnt=0; 7 | queue> rotten; 8 | for(int i=0;i=m || ny >= n || grid[nx][ny]!=1) 29 | continue; 30 | grid[nx][ny]=2; 31 | rotten.push({nx,ny}); 32 | } 33 | } 34 | if(!rotten.empty()) 35 | day++; 36 | } 37 | return tot==cnt ? day : -1; 38 | } 39 | }; -------------------------------------------------------------------------------- /Intuit/3.Course_Schedule.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findOrder(int numCourses, vector>& prerequisites) { 4 | vector res ; 5 | vector indegree(numCourses ,0) ; 6 | vector> graph(numCourses,vector()) ; 7 | 8 | for (vector &pre : prerequisites) { 9 | graph[pre[1]].push_back(pre[0]); 10 | indegree[pre[0]] ++ ; 11 | } 12 | 13 | queue q ; 14 | for(int i=0;i 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | 7 | class Solution 8 | { 9 | public: 10 | //Function to return k largest elements from an array. 11 | vector kLargest(int arr[], int n, int k) 12 | { 13 | vector v; 14 | priority_queue pq(arr,arr+n); 15 | while(k!=0) 16 | { 17 | v.push_back(pq.top()); 18 | pq.pop(); 19 | k--; 20 | } 21 | return v ; 22 | } 23 | }; 24 | 25 | // { Driver Code Starts. 26 | 27 | int main(){ 28 | int t; 29 | cin >> t; 30 | while(t--){ 31 | int n, k; 32 | cin >> n >> k; 33 | 34 | int arr[n]; 35 | for(int i = 0; i < n;i++) 36 | cin>>arr[i]; 37 | Solution ob; 38 | vector result = ob.kLargest(arr, n, k); 39 | for (int i = 0; i < result.size(); ++i) 40 | cout< 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | // User function Template for C++ 9 | 10 | class Solution{ 11 | public: 12 | int minSteps(int D , int pos =0 , int lastStep =0 ){ 13 | // code here 14 | int steps = ((double)-1 + sqrt(1 + 8*D)) /(double) 2; 15 | 16 | int coverage = (steps * (steps + 1))/2; 17 | 18 | if(coverage == D) 19 | return steps; 20 | 21 | for(int i = 0; i < 3; ++i) { 22 | ++steps; 23 | coverage += steps; 24 | if(((coverage - D) & 1) == 0) 25 | { 26 | return steps; 27 | } 28 | } 29 | 30 | } 31 | }; 32 | 33 | // { Driver Code Starts. 34 | 35 | int main(){ 36 | int t; 37 | cin>>t; 38 | while(t--){ 39 | int D; 40 | cin>>D; 41 | 42 | Solution ob; 43 | cout< randPoint() { 12 | vector v ; 13 | double length ; 14 | double theta ; 15 | 16 | double random = (double) rand() / RAND_MAX ; 17 | theta = random * 2 * 3.14159 ; 18 | 19 | double random2 = (double) rand() / RAND_MAX ; 20 | length = sqrt(random2) * r ; 21 | 22 | double x_r = x + length*cos(theta) ; 23 | double y_r = y + length * sin(theta) ; 24 | 25 | v.push_back(x_r) ; 26 | v.push_back(y_r) ; 27 | 28 | return v ; 29 | 30 | 31 | } 32 | }; 33 | 34 | /** 35 | * Your Solution object will be instantiated and called as such: 36 | * Solution* obj = new Solution(radius, x_center, y_center); 37 | * vector param_1 = obj->randPoint(); 38 | */ -------------------------------------------------------------------------------- /Amazon/Maximum_Profit.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | // Initial template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | // User function Template for C++ 9 | 10 | class Solution { 11 | public: 12 | int maxProfit(int K, int N, int A[]) { 13 | vector> dp(K+1,vector (N+1,0)) ; 14 | // 15 | for(int i=1 ;i<=K; i++) { 16 | for(int j= 1; j<=N ; j ++) { 17 | dp[i][j] = dp[i][j-1] ; 18 | for(int p =0 ; p> t; 33 | while (t--) { 34 | int N, K; 35 | cin >> K; 36 | cin >> N; 37 | int A[N]; 38 | for (int i = 0; i < N; i++) cin >> A[i]; 39 | 40 | Solution ob; 41 | cout << ob.maxProfit(K, N, A) << endl; 42 | } 43 | return 0; 44 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Intuit/7. Capacity To Ship Packages Within D Days.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool ispossible(vector& weights, int days, int mid) { 4 | int d =1 ; 5 | int sum =0 ; 6 | for(int i=0;i mid) { 9 | d ++ ; 10 | sum = weights[i] ; 11 | } 12 | } 13 | return d<=days ; 14 | } 15 | 16 | int shipWithinDays(vector& weights, int days) { 17 | int maxi =0 ; 18 | int sum =0 ; 19 | for(auto val : weights) 20 | { 21 | sum += val ; 22 | maxi = max(maxi , val) ; 23 | } 24 | int lo = maxi ; 25 | int hi = sum ; 26 | int ans ; 27 | while(lo <= hi) { 28 | int mid = lo + (hi-lo)/2 ; 29 | if(ispossible(weights,days,mid)==true) 30 | { 31 | ans = mid ; 32 | hi = mid -1 ; 33 | } 34 | else { 35 | lo = mid +1 ; 36 | } 37 | } 38 | return ans ; 39 | } 40 | }; -------------------------------------------------------------------------------- /Intuit/6.Split Array Largest Sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | 4 | bool ispossible(vector& nums, int m , int mid) 5 | { 6 | int sa_count =1 ; 7 | int sum =0 ; 8 | for(int i =0 ; i< nums.size() ; i++) 9 | { 10 | sum += nums[i] ; 11 | if(sum > mid) 12 | { 13 | sa_count ++ ; 14 | sum = nums[i] ; 15 | } 16 | } 17 | 18 | return sa_count <= m ; 19 | } 20 | 21 | int splitArray(vector& nums, int m) { 22 | int maxi =0 ; 23 | int sum =0 ; 24 | for(auto val : nums) { 25 | sum += val ; 26 | maxi = max(maxi , val) ; 27 | } 28 | int lo = maxi ; 29 | int hi = sum ; 30 | int ans ; 31 | while(lo <= hi) { 32 | int mid = lo + (hi-lo)/2 ; 33 | if(ispossible(nums,m,mid)==true) { 34 | ans = mid ; 35 | hi = mid -1 ; 36 | } 37 | else { 38 | lo = mid +1 ; 39 | } 40 | } 41 | return ans ; 42 | } 43 | }; -------------------------------------------------------------------------------- /Walmart/8. Numbers of unique Path .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | //Initial template for C++ 3 | #include 4 | using namespace std; 5 | 6 | // } Driver Code Ends 7 | //User function template in C++ 8 | 9 | class Solution 10 | { 11 | public: 12 | //Function to find total number of unique paths. 13 | int NumberOfPath(int a, int b) 14 | { 15 | int dp[a][b] ; 16 | for(int i=0 ; i< a ; i++) dp[i][0] = 1 ; 17 | for(int i=0 ; i< b ; i++) dp[0][i] = 1 ; 18 | for(int i=1 ; i< a ; i++) { 19 | for(int j=1 ; j< b ; j++) { 20 | dp[i][j] = dp[i-1][j] + dp[i][j-1] ; 21 | } 22 | } 23 | 24 | int ans = dp[a-1][b-1] ; 25 | return ans ; 26 | } 27 | }; 28 | 29 | 30 | // { Driver Code Starts. 31 | int main() 32 | { 33 | //taking total testcases 34 | int t; 35 | cin>>t; 36 | while(t--) 37 | { 38 | //taking dimensions of the matrix 39 | int a,b; 40 | cin>>a>>b; 41 | Solution ob; 42 | //calling NumberOfPath() function 43 | cout << ob.NumberOfPath(a,b) << endl; 44 | } 45 | } 46 | 47 | // } Driver Code Ends -------------------------------------------------------------------------------- /Microsoft/Stickler_Thief .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | typedef long long int ll; 5 | 6 | // } Driver Code Ends 7 | class Solution 8 | { 9 | public: 10 | //Function to find the maximum money the thief can get. 11 | int FindMaxSum(int p[], int n) 12 | { 13 | if(n==1) 14 | return p[0] ; 15 | 16 | if(n==2) 17 | return max(p[0],p[1]) ; 18 | 19 | p[2] = max(p[1] , p[0] + p[2]) ; 20 | 21 | for(int i=3 ; i>t; 36 | while(t--) 37 | { 38 | //taking number of houses 39 | int n; 40 | cin>>n; 41 | int a[n]; 42 | 43 | //inserting money of each house in the array 44 | for(int i=0;i>a[i]; 46 | Solution ob; 47 | //calling function FindMaxSum() 48 | cout< 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution{ 7 | public: 8 | string printMinNumberForPattern(string S){ 9 | string res ; 10 | stack st; 11 | int num = 1; 12 | for(auto it: S){ 13 | if(it == 'D'){ 14 | st.push(num); 15 | num++; 16 | }else{ 17 | st.push(num); 18 | num++; 19 | while(!st.empty()){ 20 | res += to_string(st.top()); 21 | st.pop(); 22 | } 23 | } 24 | } 25 | st.push(num); 26 | while(!st.empty()){ 27 | res += to_string(st.top()); 28 | st.pop(); 29 | } 30 | return res ; 31 | } 32 | }; 33 | 34 | 35 | // { Driver Code Starts. 36 | int main() 37 | { 38 | int t; 39 | cin>>t; 40 | while(t--) 41 | { 42 | string S; 43 | cin >> S; 44 | Solution ob; 45 | cout << ob.printMinNumberForPattern(S) << endl; 46 | } 47 | return 0; 48 | } 49 | // } Driver Code Ends -------------------------------------------------------------------------------- /Adobe/Implement_atoi.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int myAtoi(string str) 4 | { 5 | long long i =0 ; 6 | int sign = 1; 7 | long long result = 0; 8 | 9 | // count all the spaces ih the string in the i variable 10 | while(str[i] == ' ') 11 | { 12 | i++ ; 13 | } 14 | 15 | // if not a digit 16 | if(isdigit(str[i]) == false) 17 | { 18 | if(str[i] == '-') { 19 | sign = -1 ; 20 | i++; 21 | } 22 | else 23 | if(str[i] == '+') 24 | i++; 25 | } 26 | // if it is a digit then traverse the string untill the next non digit char 27 | 28 | while(isdigit(str[i]) == true) 29 | { 30 | result = (result*10) + (str[i]-'0'); 31 | 32 | // cheack for the result is it in the integer range or not ? 33 | if(result > INT_MAX || result < INT_MIN) 34 | { 35 | return (sign == -1) ? INT_MIN : INT_MAX; 36 | } 37 | 38 | 39 | i++; 40 | } 41 | int num = result * sign ; 42 | 43 | return num ; 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /Intuit/Question Links here.txt: -------------------------------------------------------------------------------- 1 | https://docs.google.com/document/d/18oi6OlvcL3wYn20Jb9crW7NO4cGkL6vUfTvplNDGkTw/edit 2 | 3 | 4 | 5 | Arsh Intuit Sheet : 6 | 7 | 1.https://www.geeksforgeeks.org/partition-a-set-into-two-subsets-such-that-the-difference-of-subset-sums-is-minimum/ 8 | 9 | 2.https://practice.geeksforgeeks.org/problems/word-search/1/ 10 | 11 | 3.https://practice.geeksforgeeks.org/problems/find-the-missing-no-in-string/1/ 12 | 13 | 4.https://practice.geeksforgeeks.org/problems/largest-number-in-k-swaps-1587115620/1 14 | 15 | 5.https://leetcode.com/problems/split-array-largest-sum/ 16 | 17 | 6.https://leetcode.com/problems/find-in-mountain-array 18 | 19 | 7.https://leetcode.com/problems/capacity-to-ship-packages-within-d-days 20 | 21 | 8.https://leetcode.com/problems/number-of-boomerangs/ 22 | 23 | 9. https://leetcode.com/problems/pacific-atlantic-water-flow/ 24 | 25 | 10.https://leetcode.com/problems/number-of-provinces/ 26 | 27 | 11.https://leetcode.com/problems/construct-quad-tree/ 28 | 29 | 12.https://leetcode.com/problems/course-schedule-ii/ 30 | 31 | 13.https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid 32 | 33 | 14.https://leetcode.com/problems/as-far-from-land-as-possible/ 34 | 35 | 15.https://leetcode.com/problems/koko-eating-bananas/ 36 | 37 | 38 | -------------------------------------------------------------------------------- /Goldman Sachs/_8_TotalDecodingMessages.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution { 7 | public: 8 | int CountWays(string str){ 9 | int N = str.size() ; 10 | 11 | long long dp[N+1] ; 12 | dp[0] =1 ; 13 | dp[1] =1 ; 14 | if(str[0] == '0') 15 | return 0 ; 16 | 17 | long long mod = 1000000007 ; 18 | for (int i=2 ; i<= N ; i++) 19 | { 20 | dp[i] =0 ; 21 | if(str[i-1] > '0') 22 | dp[i] = dp[i-1] ; 23 | 24 | int b =(str[i-2]-'0') * 10 + (str[i-1] - '0') ; 25 | 26 | if(b==0) 27 | return 0 ; 28 | 29 | if( 10 <=b and b<= 26) 30 | { 31 | dp[i] = (dp[i] %mod + dp[i-2] % mod) % mod ; 32 | 33 | } 34 | 35 | } 36 | return (int) dp[N] ; 37 | 38 | } 39 | 40 | }; 41 | 42 | // { Driver Code Starts. 43 | int main(){ 44 | int tc; 45 | cin >> tc; 46 | while(tc--){ 47 | string str; 48 | cin >> str; 49 | Solution obj; 50 | int ans = obj.CountWays(str); 51 | cout << ans << "\n"; 52 | } 53 | return 0; 54 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Adobe/Minimum operations to convert array A to B .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | 6 | // } Driver Code Ends 7 | //User function Template for C++ 8 | 9 | class Solution { 10 | public: 11 | int minInsAndDel(int A[], int B[], int N, int M) 12 | { 13 | 14 | vector LIS ; // store the longest increasing subsequesnce in the (NLOGN) time 15 | 16 | unordered_set set; 17 | 18 | for(int i = 0 ; i < M; i++) { 19 | set.insert(B[i]); 20 | } 21 | 22 | for(int i = 0; i < N; i++) 23 | { 24 | if(set.find(A[i]) !=set.end()) 25 | { 26 | auto x = lower_bound(LIS.begin(), LIS.end(), A[i]); 27 | 28 | if(x == LIS.end()) 29 | // means A is in order of B ..therefore push_element at back 30 | { 31 | LIS.push_back(A[i]); 32 | } 33 | else /// just replace with the element which is greater or equal to that element 34 | *x = A[i]; 35 | } 36 | } 37 | // lis is the longest vector of elemets in both the array 38 | return (N+M- 2* LIS.size()) ; 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /Walmart/15. Find Array Given Subset Sums.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector recoverArray(int n, vector& sums) 4 | { 5 | sort(begin(sums),end(sums)) ; 6 | 7 | vector ans ; 8 | 9 | while(n--) { 10 | int d = sums[1] - sums[0] ; 11 | 12 | unordered_map f ; 13 | 14 | vector a,b ; 15 | // two subsets 16 | bool ok = false ; 17 | for(auto & x : sums) 18 | { 19 | if(!f[x]) 20 | { 21 | a.push_back(x) ; 22 | f[x+d] ++ ; 23 | if(x==0) ok = true ; 24 | } 25 | else 26 | { 27 | b.push_back(x) ; 28 | f[x]-- ; 29 | } 30 | } 31 | 32 | if(ok==true) 33 | { 34 | ans.push_back(d) ; 35 | sums = a ; 36 | } 37 | else 38 | { 39 | ans.push_back(-d) ; 40 | sums =b ; 41 | } 42 | } 43 | 44 | 45 | return ans ; 46 | } 47 | }; -------------------------------------------------------------------------------- /Microsoft/Stock_span.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | 6 | // } Driver Code Ends 7 | 8 | 9 | 10 | class Solution 11 | { 12 | public: 13 | //Function to calculate the span of stock’s price for all n days. 14 | vector calculateSpan(int price[], int n) 15 | { 16 | vectorans(n) ; 17 | ans[0] = 1 ; 18 | stack prev ; 19 | prev.push(0); 20 | 21 | for(int i = 1; i < n; i ++) 22 | { 23 | while(!prev.empty() and price[prev.top()] <= price[i]) 24 | { 25 | prev.pop(); 26 | } 27 | 28 | ans[i] = i - (prev.empty() ? -1 : prev.top()); 29 | prev.push(i); 30 | } 31 | 32 | return ans ; 33 | } 34 | }; 35 | 36 | 37 | 38 | // { Driver Code Starts. 39 | 40 | int main() 41 | { 42 | int t; 43 | cin>>t; 44 | while(t--) 45 | { 46 | int n; 47 | cin>>n; 48 | int i,a[n]; 49 | for(i=0;i>a[i]; 52 | } 53 | Solution obj; 54 | vector s = obj.calculateSpan(a, n); 55 | 56 | for(i=0;i 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution{ 7 | 8 | public: 9 | int minDifference(int arr[], int n) 10 | { 11 | sort(arr,arr+n) ; 12 | int sum ; 13 | sum = accumulate(arr,arr+n,0) ; 14 | int half = sum/2 ; 15 | vector> dp(n+1 , vector (half+1 ,0)) ; 16 | 17 | for(int i=0;i> t; 43 | while (t--) 44 | { 45 | int n; 46 | cin >> n; 47 | 48 | int a[n]; 49 | for(int i = 0; i < n; i++) 50 | cin >> a[i]; 51 | 52 | 53 | 54 | Solution ob; 55 | cout << ob.minDifference(a, n) << "\n"; 56 | 57 | } 58 | return 0; 59 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Microsoft/minimum_sum_partition.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution{ 7 | 8 | public: 9 | int minDifference(int arr[], int n) 10 | { 11 | sort(arr,arr+n) ; 12 | int sum ; 13 | sum = accumulate(arr,arr+n,0) ; 14 | int half = sum/2 ; 15 | vector> dp(n+1 , vector (half+1 ,0)) ; 16 | 17 | for(int i=0;i> t; 43 | while (t--) 44 | { 45 | int n; 46 | cin >> n; 47 | 48 | int a[n]; 49 | for(int i = 0; i < n; i++) 50 | cin >> a[i]; 51 | 52 | 53 | 54 | Solution ob; 55 | cout << ob.minDifference(a, n) << "\n"; 56 | 57 | } 58 | return 0; 59 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Walmart/14. Path with Maximum Probability.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | double maxProbability(int n, vector>& edges, vector& succProb, int start, int end) 4 | { 5 | 6 | vector>> next(n) ; 7 | int N = edges.size() ; 8 | 9 | for(int i=0;i prob(n) ; 18 | 19 | prob[start]=1 ; 20 | 21 | queue q ; 22 | q.push(start) ; 23 | 24 | while(!q.empty()) 25 | { 26 | int curr = q.front() ; 27 | q.pop() ; 28 | 29 | for(auto x : next[curr]) 30 | { 31 | 32 | if(prob[x.first] >= prob[curr] * x.second) 33 | continue ; 34 | 35 | prob[x.first] = prob[curr] * x.second ; 36 | 37 | q.push(x.first) ; 38 | } 39 | } 40 | 41 | 42 | return prob[end] ; 43 | 44 | 45 | } 46 | }; -------------------------------------------------------------------------------- /Goldman Sachs/_13_DecodeTheString.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // } Driver Code Ends 5 | // User function Template for C++ 6 | 7 | class Solution{ 8 | public: 9 | string decode(string&s, int & idx) { 10 | int times =0 ; 11 | string word= "" ; 12 | while(idx < s.length()) { 13 | if(s[idx] >= '0' && s[idx] <= '9') 14 | { 15 | times = times* 10 + (s[idx] - '0') ; 16 | } 17 | else if(s[idx] == '[') 18 | { 19 | idx++; 20 | string temp = decode(s, idx); 21 | while(times--) word += temp; 22 | times = 0; 23 | } 24 | else if(s[idx] == ']') 25 | return word; 26 | else 27 | word += s[idx]; 28 | idx++; 29 | } 30 | return word ; 31 | } 32 | 33 | 34 | string decodedString(string s){ 35 | int idx = 0; 36 | return decode(s, idx); 37 | } 38 | }; 39 | 40 | // { Driver Code Starts. 41 | 42 | int main(){ 43 | int t; 44 | cin>>t; 45 | while(t--){ 46 | string s; 47 | cin>>s; 48 | 49 | Solution ob; 50 | cout< 5 | using namespace std; 6 | vector AllParenthesis(int n) ; 7 | 8 | 9 | // } Driver Code Ends 10 | //User function Template for C++ 11 | 12 | // N is the number of pairs of parentheses 13 | // Return list of all combinations of balanced parantheses 14 | class Solution 15 | { 16 | public: 17 | void solve(int n,string s,int open,int close,vector&ans) 18 | { 19 | if(open>n || close>n || close>open) { 20 | return ; 21 | } 22 | if(s.length()==2*n and open==close) 23 | ans.push_back(s); 24 | 25 | solve(n,s+'(',open+1,close,ans); 26 | solve(n,s+')',open,close+1, ans); 27 | } 28 | 29 | 30 | 31 | vector AllParenthesis(int n) 32 | { 33 | // Your code goes here 34 | vector ans ; 35 | string s = "" ; 36 | solve(n,s,0,0,ans) ; 37 | return ans ; 38 | } 39 | }; 40 | 41 | // { Driver Code Starts. 42 | 43 | 44 | int main() 45 | { 46 | int t; 47 | cin>>t; 48 | while(t--) 49 | { 50 | int n; 51 | cin>>n; 52 | Solution ob; 53 | vector result = ob.AllParenthesis(n); 54 | sort(result.begin(),result.end()); 55 | for (int i = 0; i < result.size(); ++i) 56 | cout< 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution 7 | { 8 | public: 9 | string FirstNonRepeating(string A){ 10 | string s = "" ; 11 | // non repeating characters queue 12 | queue q; 13 | int n = A.length() ; 14 | 15 | vector used(26, false); 16 | 17 | 18 | for(int i = 0; i < n ; ++i) { 19 | char c = A[i] , output; 20 | 21 | if(used[c - 'a'] < 1) 22 | { 23 | q.push(c); 24 | } 25 | ++used[c - 'a']; 26 | 27 | while(!q.empty() and used[q.front() - 'a'] > 1) 28 | { 29 | q.pop(); 30 | } 31 | 32 | if(q.empty()) { 33 | output = '#'; 34 | } 35 | else { 36 | output = q.front(); 37 | } 38 | s += output; 39 | } 40 | 41 | 42 | return s ; 43 | } 44 | 45 | }; 46 | 47 | // { Driver Code Starts. 48 | int main(){ 49 | int tc; 50 | cin >> tc; 51 | while(tc--){ 52 | string A; 53 | cin >> A; 54 | Solution obj; 55 | string ans = obj.FirstNonRepeating(A); 56 | cout << ans << "\n"; 57 | } 58 | return 0; 59 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Adobe/partition Equal Subset Sum .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | // Initial Template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | // User function Template for C++ 9 | 10 | class Solution{ 11 | public: 12 | int equalPartition(int N, int arr[]) 13 | { 14 | sort(arr,arr+N) ; 15 | int sum = accumulate(arr,arr+N , 0) ; 16 | if(sum & 1) return 0 ; 17 | int K = sum /2 ; 18 | vector> dp(N+1 , vector (K+1,0)) ; 19 | for(int i=0;i>t; 42 | while(t--){ 43 | int N; 44 | cin>>N; 45 | int arr[N]; 46 | for(int i = 0;i < N;i++) 47 | cin>>arr[i]; 48 | 49 | Solution ob; 50 | if(ob.equalPartition(N, arr)) 51 | cout<<"YES\n"; 52 | else 53 | cout<<"NO\n"; 54 | } 55 | return 0; 56 | } // } Driver Code Ends 57 | -------------------------------------------------------------------------------- /Intuit/14. Minimum Swaps to Arrange a Binary Grid.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minSwaps(vector>& grid) 4 | { 5 | int n = grid.size() ; vectorarr(n); 6 | 7 | for(int i=0; i=0; j--) 11 | { 12 | if(grid[i][j] !=0) 13 | { 14 | break; 15 | } 16 | count++; 17 | } 18 | arr[i] = count; 19 | } 20 | 21 | int swaps = 0; 22 | for(int i=0;i= req_trailing_zero) 27 | { 28 | continue; 29 | } 30 | int val = arr[i] ; 31 | int j = i+1 ; 32 | while(j= req_trailing_zero) 36 | { 37 | break; 38 | } 39 | j++ ; 40 | } 41 | 42 | if(j == n) 43 | { 44 | return -1; 45 | } 46 | swaps += (j-i) ; // for this window 47 | arr[i] = val ; 48 | } 49 | 50 | return swaps ; 51 | } 52 | }; -------------------------------------------------------------------------------- /Adobe/Number of distict Words with k maximum contiguous vowels .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | //Initial Template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | 8 | // } Driver Code Ends 9 | //User function Template for C++ 10 | 11 | class Solution 12 | { 13 | public: 14 | 15 | #define ll long long 16 | #define mod (ll) (1e9 +7) 17 | 18 | 19 | int kvowelwords(int N, int K) { 20 | vector> dp (N+1 , vector (K+1 , 0)) ; 21 | 22 | for(int i=0;i<=N ; i++) 23 | { 24 | for(int j= 0 ; j<=K ; ++j) 25 | { 26 | 27 | if(i==0) { // initial condition 28 | dp[i][j] = 1 ; 29 | } 30 | else { 31 | dp[i][j] = (dp[i-1][K] * 21) % mod ; 32 | 33 | if(j>0) { 34 | dp[i][j] = (dp[i][j] + dp[i-1][j-1] *5 % mod) % mod ; 35 | } 36 | } 37 | } 38 | } 39 | return dp[N][K] ; 40 | } 41 | }; 42 | 43 | 44 | // { Driver Code Starts. 45 | 46 | 47 | int main() 48 | { 49 | int t; 50 | cin >> t; 51 | while (t--) 52 | { 53 | int N;int K; 54 | cin >>N>>K; 55 | 56 | Solution ob; 57 | int ans = ob.kvowelwords(N,K); 58 | cout << ans << endl; 59 | } 60 | return 0; 61 | } // } Driver Code Ends 62 | -------------------------------------------------------------------------------- /Microsoft/Rotate_by_90-degree.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | //Initial template for C++ 3 | 4 | #include 5 | using namespace std; 6 | void rotate (vector >& matrix); 7 | //User function template for C++ 8 | 9 | /* matrix : given input matrix, you are require 10 | to change it in place without using extra space */ 11 | void rotate(vector >& m) 12 | { 13 | // Your code goes here 14 | int n = m.size() ; 15 | 16 | // transpose 17 | for(int i=0; i>t; 37 | while(t--) 38 | { 39 | int n; 40 | cin>>n; 41 | vector > matrix(n); 42 | for(int i=0; i>matrix[i][j]; 47 | } 48 | rotate(matrix); 49 | for (int i = 0; i < n; ++i) 50 | { 51 | for(int j=0; j 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | 7 | class Solution{ 8 | public: 9 | int countSubArrayProductLessThanK(const vector& a, int n, long long k) { 10 | long long prod=1; 11 | int ans=0; 12 | int j=0; 13 | for(int i=0;i=k) 18 | { 19 | while(j0) 20 | { 21 | prod=prod/a[j]; 22 | 23 | if(prod> t; 44 | while (t--) { 45 | int n, i; 46 | long long int k; 47 | cin >> n >> k; 48 | vector arr(n); 49 | for (i = 0; i < n; i++) cin >> arr[i]; 50 | Solution obj; 51 | cout << obj.countSubArrayProductLessThanK(arr, n, k) << endl; 52 | } 53 | return 0; 54 | } 55 | // } Driver Code Ends -------------------------------------------------------------------------------- /Amazon/IPL 2021 - Match Day 2 .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution { 7 | public: 8 | vector max_of_subarrays(vector arr, int n, int k) { 9 | vector ans ; 10 | 11 | 12 | // maxheap approach 13 | priority_queue< pair > mheap ; 14 | 15 | // push only first k element s in the heap 16 | for(int i=0;i> t; 43 | 44 | while (t--) { 45 | 46 | int n, k; 47 | cin >> n >> k; 48 | 49 | vector arr(n); 50 | for (int i = 0; i < n; i++) cin >> arr[i]; 51 | Solution ob; 52 | vector res = ob.max_of_subarrays(arr, n, k); 53 | for (int i = 0; i < res.size(); i++) cout << res[i] << " "; 54 | cout << endl; 55 | } 56 | 57 | return 0; 58 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Walmart/1. Power Of Numbers.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | # define mod 1000000007 5 | 6 | // } Driver Code Ends 7 | class Solution{ 8 | public: 9 | //You need to complete this fucntion 10 | 11 | long long power(int N,int R) 12 | { 13 | return solve(N ,R) % 1000000007 ; 14 | 15 | } 16 | 17 | long long solve(int N ,int R) { 18 | if(R==0) return 1 ; 19 | 20 | long long result = power(N,R/2) ; 21 | result = (result *result) % 1000000007 ; 22 | if(R&1) 23 | return N * result ; 24 | else 25 | return result ; 26 | } 27 | 28 | }; 29 | 30 | // { Driver Code Starts. 31 | 32 | // compute reverse of a number 33 | long long rev(long long n) 34 | { 35 | long long rev_num = 0; 36 | while(n > 0) 37 | { 38 | rev_num = rev_num*10 + n%10; 39 | n = n/10; 40 | } 41 | return rev_num; 42 | } 43 | 44 | 45 | 46 | 47 | int main() 48 | { 49 | int T; 50 | cin>>T;//testcases 51 | 52 | while(T--) 53 | { 54 | long long N; 55 | cin>>N;//input N 56 | 57 | long long R = 0; 58 | 59 | // reverse the given number n 60 | R = rev(N); 61 | Solution ob; 62 | //power of the number to it's reverse 63 | long long ans =ob.power(N,R); 64 | cout << ans< 5 | using namespace std; 6 | 7 | 8 | class Solution 9 | { 10 | public: 11 | int isValid(vector> mat) 12 | { 13 | int row[9][9] = {0} ; 14 | int col[9][9] = {0} ; 15 | int box[9][9] = {0} ; 16 | 17 | 18 | 19 | for(int i=0;i<9;++i) { 20 | for(int j=0; j <9 ; ++j) { 21 | if(mat[i][j]!=0) 22 | { 23 | row[i][mat[i][j]-1] ++ ; 24 | col[j][mat[i][j]-1] ++ ; 25 | box[(i/3) * 3 + (j/3)][mat[i][j]-1] ++ ; 26 | 27 | 28 | // imp cond check 29 | if(row[i][mat[i][j]-1] > 1 or 30 | col[j][mat[i][j]-1] >1 or box[(i/3) * 3 + (j/3)][mat[i][j]-1] > 1) 31 | { 32 | return false ; 33 | } 34 | 35 | } 36 | } 37 | } 38 | 39 | 40 | 41 | 42 | return true ; 43 | 44 | } 45 | }; 46 | 47 | // { Driver Code Starts. 48 | 49 | int main(){ 50 | int t; 51 | cin>>t; 52 | while(t--){ 53 | vector> mat(9, vector(9, 0)); 54 | for(int i = 0;i < 81;i++) 55 | cin>>mat[i/9][i%9]; 56 | 57 | Solution ob; 58 | cout< 5 | using namespace std; 6 | 7 | 8 | // } Driver Code Ends 9 | 10 | 11 | class Solution{ 12 | //Function to find the leaders in the array. 13 | public: 14 | vector leaders(int a[], int n) 15 | { 16 | vector v ; 17 | int leader = a[n-1] ; 18 | 19 | for(int i=n-2 ; i >=0 ; i--) 20 | { 21 | if(a[i] >= leader) 22 | { 23 | leader = a[i] ; 24 | v.push_back(a[i]) ; 25 | } 26 | } 27 | reverse(v.begin() , v.end()) ; 28 | 29 | v.push_back(a[n-1]) ; // push the original leader 30 | 31 | return v ; 32 | } 33 | }; 34 | 35 | // { Driver Code Starts. 36 | 37 | int main() 38 | { 39 | long long t; 40 | cin >> t;//testcases 41 | while (t--) 42 | { 43 | long long n; 44 | cin >> n;//total size of array 45 | 46 | int a[n]; 47 | 48 | //inserting elements in the array 49 | for(long long i =0;i> a[i]; 51 | } 52 | Solution obj; 53 | //calling leaders() function 54 | vector v = obj.leaders(a, n); 55 | 56 | //printing elements of the vector 57 | for(auto it = v.begin();it!=v.end();it++){ 58 | cout << *it << " "; 59 | } 60 | 61 | cout << endl; 62 | 63 | } 64 | } 65 | // } Driver Code Ends -------------------------------------------------------------------------------- /Amazon/Maximum of all subarrays of size k.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | //Initial template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | 8 | // } Driver Code Ends 9 | //User function template for C++ 10 | 11 | class Solution 12 | { 13 | public: 14 | //Function to find maximum of each subarray of size k. 15 | vector max_of_subarrays(int *arr, int n, int k) 16 | { 17 | priority_queue> mheap ; 18 | 19 | for(int i = 0; i < k; ++i) { 20 | mheap.push({arr[i], i}); 21 | } 22 | 23 | vector vec ; 24 | vec.push_back(mheap.top().first); 25 | 26 | for(int i = k; i < n; ++i) 27 | { 28 | mheap.push({arr[i], i}); 29 | 30 | while(!mheap.empty() and mheap.top().second <= i - k) 31 | { 32 | mheap.pop(); 33 | } 34 | 35 | vec.push_back(mheap.top().first); 36 | } 37 | 38 | return vec ; 39 | } 40 | }; 41 | 42 | // { Driver Code Starts. 43 | 44 | int main() { 45 | 46 | int t; 47 | cin >> t; 48 | 49 | while(t--){ 50 | 51 | int n, k; 52 | cin >> n >> k; 53 | 54 | int arr[n]; 55 | for(int i = 0;i> arr[i]; 57 | Solution ob; 58 | vector res = ob.max_of_subarrays(arr, n, k); 59 | for (int i = 0; i < res.size (); i++) 60 | cout << res[i] << " "; 61 | cout << endl; 62 | 63 | } 64 | 65 | return 0; 66 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Intuit/9.Maximum number in K swaps .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | // } Driver Code Ends 5 | class Solution 6 | { 7 | public: 8 | void solve(string str , int n , int k ,string & ans , int ind ) 9 | { 10 | if(k==0) 11 | return ; 12 | 13 | char maxi = str[ind] ; 14 | 15 | for(int i = ind + 1 ; i< n ; i++) { 16 | if(maxi < str[i]) 17 | maxi = str[i] ; 18 | } 19 | 20 | if(maxi != str[ind]) k-- ; 21 | 22 | for(int i=n-1 ; i>=0 ; i--) 23 | { 24 | if(maxi == str[i]) 25 | { 26 | swap(str[ind] , str[i]) ; 27 | ans = max(ans,str) ; 28 | 29 | solve(str,n,k,ans,ind +1) ; 30 | 31 | swap(str[ind] , str[i]) ; 32 | } 33 | } 34 | } 35 | 36 | //Function to find the largest number after k swaps. 37 | string findMaximumNum(string str, int k) 38 | { 39 | // code here. 40 | string ans = str ; 41 | int n = str.length() ; 42 | solve(str,n,k,ans,0) ; 43 | return ans ; 44 | } 45 | }; 46 | 47 | // { Driver Code Starts. 48 | 49 | int main() 50 | { 51 | int t, k; 52 | string str; 53 | 54 | cin >> t; 55 | while (t--) 56 | { 57 | cin >> k >> str; 58 | Solution ob; 59 | cout<< ob.findMaximumNum(str, k) << endl; 60 | } 61 | return 0; 62 | } 63 | // } Driver Code Ends -------------------------------------------------------------------------------- /Adobe/Longest Arithmetic Progression .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | //Initial template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | //User function template for C++ 9 | 10 | class Solution{ 11 | public: 12 | int lengthOfLongestAP(int A[], int n) 13 | { 14 | int len = 2 ; 15 | // there will be two states in the dp table 16 | // one is diff 17 | // other is last element of the AP 18 | if(n<=2) return n ; 19 | // 20 | vector> dp(n) ; 21 | 22 | for(int i=0; i< n ; i++) 23 | { 24 | for(int j= i+1 ; j< n ; j++) 25 | { 26 | int diff = A[j] - A[i] ; 27 | 28 | if(dp[i].find(diff) != dp[i].end()) 29 | { 30 | dp[j][diff] = 1 + dp[i][diff] ; 31 | } 32 | else 33 | { 34 | dp[j][diff] = 2 ; 35 | } 36 | 37 | len = max(len ,dp[j][diff]) ; 38 | } 39 | } 40 | 41 | return len ; 42 | } 43 | }; 44 | 45 | // { Driver Code Starts. 46 | int main() { 47 | int t; 48 | cin >> t; 49 | while (t--) { 50 | int n; 51 | cin >> n; 52 | int A[n]; 53 | for (int i = 0; i < n; i++) { 54 | cin >> A[i]; 55 | } 56 | Solution ob; 57 | auto ans = ob.lengthOfLongestAP(A, n); 58 | cout << ans << "\n"; 59 | } 60 | return 0; 61 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Goldman Sachs/_1_PrintAnagramsTogether.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | // } Driver Code Ends 7 | //User function Template for C++ 8 | 9 | class Solution{ 10 | public: 11 | vector > Anagrams(vector& string_list) { 12 | //code here 13 | vector > ans ; 14 | unordered_map > mp ; 15 | 16 | 17 | 18 | for(int i=0;i< string_list.size() ; ++i) { 19 | string word = string_list[i] ; 20 | sort(begin(word) , end(word)) ; 21 | mp[word].push_back(string_list[i]) ; 22 | } 23 | for(auto it : mp) { 24 | ans.push_back(it.second) ; 25 | } 26 | 27 | 28 | return ans ; 29 | } 30 | }; 31 | 32 | // { Driver Code Starts. 33 | 34 | int main() 35 | { 36 | int t; 37 | cin>>t; 38 | while(t--) 39 | { 40 | int n; 41 | cin>>n; 42 | vector string_list(n); 43 | for (int i = 0; i < n; ++i) 44 | cin>>string_list[i]; 45 | Solution ob; 46 | vector > result = ob.Anagrams(string_list); 47 | sort(result.begin(),result.end()); 48 | for (int i = 0; i < result.size(); i++) 49 | { 50 | for(int j=0; j < result[i].size(); j++) 51 | { 52 | cout< 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution { 7 | public: 8 | bool canPair(vector arr , int k) 9 | { 10 | 11 | unordered_map mp; 12 | 13 | int n = arr.size(); 14 | if(n % 2 != 0) return false; 15 | 16 | for(int i=0;i> tc; 47 | while (tc--) { 48 | int n, k; 49 | cin >> n >> k; 50 | vector nums(n); 51 | for (int i = 0; i < nums.size(); i++) cin >> nums[i]; 52 | Solution ob; 53 | bool ans = ob.canPair(nums, k); 54 | if (ans) 55 | cout << "True\n"; 56 | else 57 | cout << "False\n"; 58 | } 59 | return 0; 60 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Microsoft/Bridge edge in a graph.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution 7 | { 8 | public: 9 | 10 | 11 | void dfs(int root , vector & vis , vector adj[] , int c , int d){ 12 | vis[root] = 1 ; 13 | 14 | 15 | for(auto e : adj[root]) 16 | { 17 | if((root == c and e==d) or (root==d and e==c)) 18 | { 19 | continue ; 20 | } 21 | 22 | if(!vis[e]) 23 | { 24 | dfs(e,vis,adj,c,d) ; 25 | } 26 | } 27 | } 28 | 29 | 30 | 31 | //Function to find if the given edge is a bridge in graph. 32 | int isBridge(int V, vector adj[], int c, int d) 33 | { 34 | // Code here 35 | vectorvis (V,0) ; 36 | 37 | dfs(c,vis,adj,c,d) ; 38 | if(!vis[d]) 39 | return 1 ; 40 | else 41 | return 0 ; 42 | } 43 | }; 44 | 45 | // { Driver Code Starts. 46 | 47 | 48 | int main() 49 | { 50 | int t; 51 | cin >> t; 52 | while (t--) { 53 | int V, E; 54 | cin >> V >> E; 55 | vector adj[V]; 56 | int i=0; 57 | while (i++> u >> v; 60 | adj[u].push_back (v); 61 | adj[v].push_back (u); 62 | } 63 | 64 | int c,d; 65 | cin>>c>>d; 66 | 67 | Solution obj; 68 | cout << obj.isBridge(V, adj, c, d) << "\n"; 69 | } 70 | 71 | return 0; 72 | } 73 | 74 | // } Driver Code Ends -------------------------------------------------------------------------------- /Walmart/3. Largest number in K swaps.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | 6 | // } Driver Code Ends 7 | 8 | 9 | class Solution 10 | { 11 | public: 12 | 13 | /// backtrack problem 14 | void solve(string str , int n , int k ,string & ans , int ind ) { 15 | 16 | if(k==0) return ; 17 | 18 | char maxi = str[ind] ; 19 | 20 | for(int i = ind + 1 ; i< n ; i++) 21 | { 22 | maxi = max(str[i],maxi) ; 23 | } 24 | 25 | if(maxi != str[ind]) 26 | k-- ; 27 | 28 | for(int i=n-1 ; i>=0 ; i--) 29 | { 30 | if(maxi == str[i]) 31 | { 32 | swap(str[ind] , str[i]) ; 33 | ans = max(ans,str) ; 34 | 35 | solve(str,n,k,ans,ind +1) ; 36 | swap(str[ind] , str[i]) ; 37 | } 38 | } 39 | } 40 | 41 | //Function to find the largest number after k swaps. 42 | string findMaximumNum(string str, int k) 43 | { 44 | // code here. 45 | string ans = str ; 46 | int n = str.length() ; 47 | solve(str,n,k,ans,0) ; 48 | return ans ; 49 | } 50 | }; 51 | 52 | // { Driver Code Starts. 53 | 54 | int main() 55 | { 56 | int t, k; 57 | string str; 58 | 59 | cin >> t; 60 | while (t--) 61 | { 62 | cin >> k >> str; 63 | Solution ob; 64 | cout<< ob.findMaximumNum(str, k) << endl; 65 | } 66 | return 0; 67 | } 68 | // } Driver Code Ends -------------------------------------------------------------------------------- /Adobe/Pots of Gold game .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | //Initial Template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | class Solution { 9 | public: 10 | // there are only two possibility 11 | // if we take a value then the next person can take the value from the same end 12 | // or from another end 13 | // so we just need to find the min value from both the ends taken 14 | 15 | long long t[1000][1000]; 16 | 17 | long long f(vector &a,int n,int i,int j) 18 | { 19 | // if odd 20 | if(i==j) return t[i][j]=a[i]; 21 | 22 | // if even 23 | if(j==i+1) return t[i][j]=max(a[i],a[j]); 24 | 25 | 26 | // pecompute 27 | if(t[i][j]!=-1) return t[i][j]; 28 | 29 | // inner value is taken min beacuse when 30 | //the oppent chance come it will try to leave min to min value for us 31 | return t[i][j]=max(a[i] + min(f(a,n,i+2, j), f(a,n,i+1, j-1) ), 32 | a[j]+ min(f(a,n,i+1, j-1), f(a,n,i, j-2) )) ; 33 | } 34 | 35 | 36 | 37 | int maxCoins(vector&A,int n) 38 | { 39 | memset(t,-1, sizeof t) ; 40 | 41 | return f(A,n,0,n-1) ; 42 | 43 | } 44 | }; 45 | 46 | 47 | 48 | // { Driver Code Starts. 49 | int main() { 50 | int t; 51 | cin >> t; 52 | while (t--) { 53 | int N; 54 | cin >> N; 55 | vectorA(N); 56 | for (int i = 0; i < N; i++) { 57 | cin >> A[i]; 58 | } 59 | Solution ob; 60 | cout << ob.maxCoins(A, N) << "\n"; 61 | } 62 | return 0; 63 | } 64 | // } Driver Code Ends 65 | -------------------------------------------------------------------------------- /Adobe/Winner of a election.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | 8 | // } Driver Code Ends 9 | class Solution{ 10 | public: 11 | 12 | //Function to return the name of candidate that received maximum votes. 13 | vector winner(string arr[],int n) 14 | { 15 | // Your code here 16 | // Return the string containing the name and an integer 17 | // representing the number of votes the winning candidate got 18 | unordered_map votes ; 19 | 20 | for(int i=0;i< n ; i++) 21 | { 22 | votes[arr[i]] ++ ; 23 | } 24 | 25 | 26 | unordered_map> rank ; 27 | 28 | int max_votes =0 ; 29 | 30 | for(auto cand : votes) 31 | { 32 | if(cand.second >= max_votes) 33 | { 34 | max_votes = cand.second ; 35 | rank[max_votes].push_back(cand.first) ; 36 | } 37 | } 38 | sort( begin(rank[max_votes]) , end(rank[max_votes])) ; 39 | 40 | 41 | return {rank[max_votes][0] , to_string(max_votes)} ; 42 | } 43 | }; 44 | 45 | // { Driver Code Starts. 46 | 47 | int main() 48 | { 49 | int t; 50 | cin>>t; 51 | 52 | for(int i=0;i>n; 58 | 59 | string arr[n]; 60 | 61 | for (int i=0;i>arr[i]; 63 | Solution obj; 64 | vector result = obj.winner(arr,n); 65 | 66 | cout< 3 | 4 | using namespace std; 5 | 6 | #define ull unsigned long long 7 | 8 | 9 | // } Driver Code Ends 10 | //User function template for C++ 11 | class Solution{ 12 | public: 13 | // #define ull unsigned long long 14 | /* Function to get the nth ugly number*/ 15 | ull getNthUglyNo(int n) { 16 | // code here 17 | ull ugly[n]; 18 | ull i2 = 0, i3 = 0, i5 = 0; 19 | ull next_multiple_of_2 = 2; 20 | ull next_multiple_of_3 = 3; 21 | ull next_multiple_of_5 = 5; 22 | ull next_ugly_no = 1; 23 | 24 | ugly[0] = 1; 25 | for (int i = 1; i < n; i++) 26 | { 27 | next_ugly_no = min( 28 | next_multiple_of_2, 29 | min(next_multiple_of_3, next_multiple_of_5)); 30 | ugly[i] = next_ugly_no; 31 | if (next_ugly_no == next_multiple_of_2) { 32 | i2 = i2 + 1; 33 | next_multiple_of_2 = ugly[i2] * 2; 34 | } 35 | if (next_ugly_no == next_multiple_of_3) { 36 | i3 = i3 + 1; 37 | next_multiple_of_3 = ugly[i3] * 3; 38 | } 39 | if (next_ugly_no == next_multiple_of_5) { 40 | i5 = i5 + 1; 41 | next_multiple_of_5 = ugly[i5] * 5; 42 | } 43 | } 44 | 45 | // End of for loop (i=1; i> t; 55 | while (t--) { 56 | int n; 57 | cin >> n; 58 | Solution ob; 59 | auto ans = ob.getNthUglyNo(n); 60 | cout << ans << "\n"; 61 | } 62 | return 0; 63 | } 64 | // } Driver Code Ends -------------------------------------------------------------------------------- /assets/lc.svg: -------------------------------------------------------------------------------- 1 | LEETCODELEETCODE -------------------------------------------------------------------------------- /Adobe/Subarray with given sum.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | 6 | // } Driver Code Ends 7 | class Solution 8 | { 9 | public: 10 | //Function to find a continuous sub-array which adds up to a given number. 11 | vector subarraySum(int arr[], int n, long long s) 12 | { 13 | // two pointer approach problem 14 | //left and right pointer 15 | vector vec(2,-1) ; 16 | long long curr_sum =0 ; 17 | int left =0 ; 18 | int right = 0 ; 19 | while(right < n) { 20 | if((curr_sum + arr[right]) == s) { 21 | vec[0] = left+1 ; 22 | vec[1] = right+1 ; 23 | break ; 24 | } 25 | else if((curr_sum + arr[right]) < s) { 26 | curr_sum += arr[right] ; 27 | right++ ; 28 | } 29 | else { 30 | curr_sum-= arr[left] ; 31 | left ++ ; 32 | } 33 | 34 | } 35 | if(vec[0]==-1 && vec[1]==-1) 36 | vec.pop_back() ; 37 | 38 | return vec ; 39 | } 40 | }; 41 | 42 | // { Driver Code Starts. 43 | 44 | int main() 45 | { 46 | int t; 47 | cin>>t; 48 | while(t--) 49 | { 50 | int n; 51 | long long s; 52 | cin>>n>>s; 53 | int arr[n]; 54 | const int mx = 1e9; 55 | for(int i=0;i>arr[i]; 58 | } 59 | Solution ob; 60 | vectorres; 61 | res = ob.subarraySum(arr, n, s); 62 | 63 | for(int i = 0;i 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | // User function Template for C++ 7 | 8 | class Solution{ 9 | public: 10 | string matrixChainOrder(int p[], int n) 11 | { 12 | 13 | 14 | vector>> dp(n-1, vector>(n-1)); 15 | 16 | for(int i = 0; i < n-1; ++i) 17 | { 18 | string M = ""; 19 | M += (char) ('A' + i); 20 | dp[i][i] = {0,M} ; 21 | } 22 | 23 | for(int size = 1; size <= n; ++size) 24 | { 25 | int l = 0; 26 | int m = size; 27 | while(m < n-1) 28 | { 29 | dp[l][m].first = numeric_limits::max(); 30 | 31 | for(int i = l; i < m; ++i) 32 | { 33 | int operations = dp[l][i].first + dp[i+1][m].first + p[l]*p[i+1]*p[m+1]; 34 | 35 | if(dp[l][m].first > operations) 36 | { 37 | dp[l][m].second = "(" + dp[l][i].second + dp[i+1][m].second + ")"; 38 | dp[l][m].first = operations; 39 | } 40 | 41 | } 42 | 43 | ++l; 44 | ++m; 45 | } 46 | } 47 | return dp[0].back().second ; 48 | } 49 | }; 50 | 51 | // { Driver Code Starts. 52 | 53 | int main(){ 54 | int t; 55 | cin>>t; 56 | while(t--){ 57 | int n; 58 | cin>>n; 59 | int p[n]; 60 | for(int i = 0;i < n;i++) 61 | cin>>p[i]; 62 | 63 | Solution ob; 64 | cout< 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution 7 | { 8 | public: 9 | int count = 1; // globally declare ker do best 10 | 11 | 12 | void dfs(int i, int j, vector> &grid) 13 | { 14 | int n = grid.size(); 15 | int m = grid[0].size(); 16 | if(i < 0 || j < 0 || i >= n || j >= m) return; 17 | 18 | if(grid[i][j] != 1) return; 19 | 20 | count++; 21 | 22 | grid[i][j]=0; 23 | 24 | dfs(i+1,j,grid); 25 | dfs(i,j+1,grid); 26 | dfs(i-1,j,grid); 27 | dfs(i,j-1,grid); 28 | dfs(i+1,j+1,grid); 29 | dfs(i+1,j-1,grid); 30 | dfs(i-1,j+1,grid); 31 | dfs(i-1,j-1,grid); 32 | } 33 | 34 | int findMaxArea(vector>& grid) 35 | { 36 | int r = grid.size(); 37 | int c = grid[0].size(); 38 | int Max = 0; 39 | for(int i = 0; i < r ; ++i){ 40 | for(int j = 0; j < c; ++j){ 41 | count=0; 42 | if(grid[i][j] == 1){ 43 | dfs(i,j,grid); 44 | Max = max(count, Max); 45 | } 46 | } 47 | } 48 | return Max; 49 | } 50 | }; 51 | 52 | // { Driver Code Starts. 53 | int main(){ 54 | int tc; 55 | cin >> tc; 56 | while(tc--){ 57 | int n, m; 58 | cin >> n >> m; 59 | vector>grid(n, vector(m, -1)); 60 | for(int i = 0; i < n; i++){ 61 | for(int j = 0; j < m; j++){ 62 | cin >> grid[i][j]; 63 | } 64 | } 65 | Solution obj; 66 | int ans = obj.findMaxArea(grid); 67 | cout << ans << "\n"; 68 | } 69 | return 0; 70 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Goldman Sachs/_11_FindMissingAndRepeating.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution{ 7 | public: 8 | int *findTwoElement(int *arr, int n) { 9 | int *result=new int(2); 10 | 11 | int xorr = 0 ; 12 | for (int i=0 ; i < n ; i++) 13 | { 14 | xorr^= arr[i] ; 15 | } 16 | for (int i=1 ; i <= n ; i++) 17 | { 18 | xorr^= i ; 19 | } 20 | int rsbm = xorr & -xorr ; 21 | int x= 0 , y =0 ; 22 | 23 | for (int i=0; i> t; 64 | while (t--) { 65 | int n; 66 | cin >> n; 67 | int a[n]; 68 | for (int i = 0; i < n; i++) { 69 | cin >> a[i]; 70 | } 71 | Solution ob; 72 | auto ans = ob.findTwoElement(a, n); 73 | cout << ans[0] << " " << ans[1] << "\n"; 74 | } 75 | return 0; 76 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Microsoft/Possible Words From Phone Digits.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | //Initial Template for C++ 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | 10 | // } Driver Code Ends 11 | //User function Template for C++ 12 | 13 | class Solution 14 | { 15 | public: 16 | //Function to find list of all words possible by pressing given numbers. 17 | vector possibleWords(int a[], int N) 18 | { 19 | //Your code here 20 | unordered_map> M ; 21 | M[2] = {"a", "b", "c"}; 22 | M[3] = {"d", "e", "f"}; 23 | M[4] = {"g", "h", "i"}; 24 | M[5] = {"j", "k", "l"}; 25 | M[6] = {"m", "n", "o"}; 26 | M[7] = {"p", "q", "r", "s"}; 27 | M[8] = {"t", "u", "v"}; 28 | M[9] = {"w", "x", "y", "z"}; 29 | 30 | vector first =M[a[0]] ; 31 | 32 | for(int i=1 ; i < N ; i++) 33 | { 34 | vector second = M[a[i]] ; 35 | vector res ; 36 | 37 | for(auto i :first) 38 | { 39 | for(auto j : second){ 40 | res.push_back(i+j) ; 41 | } 42 | } 43 | first = res ; 44 | } 45 | return first ; 46 | } 47 | }; 48 | 49 | 50 | // { Driver Code Starts. 51 | 52 | int main() { 53 | 54 | int T; 55 | 56 | cin >> T; //testcases 57 | 58 | while(T--){ //while testcases exist 59 | int N; 60 | 61 | cin >> N; //input size of array 62 | 63 | int a[N]; //declare the array 64 | 65 | for(int i =0;i> a[i]; //input the elements of array that are keys to be pressed 67 | } 68 | 69 | Solution obj; 70 | 71 | vector res = obj.possibleWords(a,N); 72 | for (string i : res) cout << i << " "; 73 | cout << endl; 74 | } 75 | 76 | return 0; 77 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Intuit/13. As Far from Land as Possible .cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxDistance(vector>& grid) { 4 | int n = grid.size(); 5 | 6 | vector>visited (n,vector(n,0)); 7 | 8 | queue> q ; 9 | // BFS approach 10 | 11 | int water = 0; 12 | for(int i=0;i>DIR = {{0,1},{1,0},{0,-1},{-1,0}}; 33 | 34 | int res = -1; 35 | while(!q.empty()) 36 | { 37 | 38 | int K = q.size(); 39 | //cout<= 0 && new_r < n && new_c >= 0 && new_c < n && !visited[new_r][new_c]) 56 | { 57 | q.push ({new_r,new_c}); 58 | visited[new_r][new_c] = 1; 59 | } 60 | } 61 | 62 | } 63 | res++; 64 | } 65 | 66 | 67 | return res; 68 | } 69 | }; -------------------------------------------------------------------------------- /Microsoft/Find All Four Sum Numbers.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | 6 | // } Driver Code Ends 7 | // User function template for C++ 8 | 9 | class Solution{ 10 | public: 11 | 12 | vector > fourSum(vector &arr, int k) { 13 | 14 | int n =arr.size() ; 15 | sort(begin(arr), end(arr)) ; 16 | vector> ans ; 17 | set> S ; 18 | 19 | for(int i=0; ik) { 33 | end -- ; 34 | } 35 | else { 36 | start ++ ; 37 | } 38 | 39 | } 40 | } 41 | } 42 | 43 | 44 | for(auto x : S) { 45 | ans.push_back(x) ; 46 | } 47 | 48 | return ans ; 49 | 50 | } 51 | }; 52 | 53 | // { Driver Code Starts. 54 | int main() { 55 | int t; 56 | cin >> t; 57 | while (t--) { 58 | int n, k, i; 59 | cin >> n >> k; 60 | vector a(n); 61 | for (i = 0; i < n; i++) { 62 | cin >> a[i]; 63 | } 64 | Solution ob; 65 | vector > ans = ob.fourSum(a, k); 66 | for (auto &v : ans) { 67 | for (int &u : v) { 68 | cout << u << " "; 69 | } 70 | cout << "$"; 71 | } 72 | if (ans.empty()) { 73 | cout << -1; 74 | } 75 | cout << "\n"; 76 | } 77 | return 0; 78 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Amazon/Nuts and Bolts Problem.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | 4 | using namespace std; 5 | 6 | 7 | // } Driver Code Ends 8 | //User function template for C++ 9 | class Solution{ 10 | public: 11 | 12 | void matchPairs(char nuts[], char bolts[], int n) 13 | { 14 | // align nuts and bolts 15 | for(int i = 0; i < n; ++i) 16 | { 17 | for(int j = i; j < n; ++j) 18 | { 19 | if(bolts[j] == nuts[i]) 20 | { 21 | char temp = bolts[i]; 22 | bolts[i] = bolts[j]; 23 | bolts[j] = temp; 24 | continue; 25 | } 26 | } 27 | } 28 | 29 | // find original position in an array 30 | vector order(n); 31 | iota(order.begin(), order.end(), 0); 32 | sort(order.begin(), order.end(), [&](int i, int j) { 33 | return nuts[i] < bolts[j]; 34 | }); 35 | 36 | // place nuts and bolts on its original position 37 | for(int i = 0; i < n; ++i) { 38 | nuts[i] = bolts[order[i]]; 39 | } 40 | for(int j = 0; j < n; ++j) { 41 | bolts[j] = nuts[j]; 42 | } 43 | 44 | } 45 | 46 | }; 47 | 48 | // { Driver Code Starts. 49 | 50 | int main() { 51 | int t; 52 | cin >> t; 53 | while (t--) { 54 | int n; 55 | cin >> n; 56 | char nuts[n], bolts[n]; 57 | for (int i = 0; i < n; i++) { 58 | cin >> nuts[i]; 59 | } 60 | for (int i = 0; i < n; i++) { 61 | cin >> bolts[i]; 62 | } 63 | Solution ob; 64 | ob.matchPairs(nuts, bolts, n); 65 | for (int i = 0; i < n; i++) { 66 | cout << nuts[i] << " "; 67 | } 68 | cout << "\n"; 69 | for (int i = 0; i < n; i++) { 70 | cout << bolts[i] << " "; 71 | } 72 | cout << "\n"; 73 | } 74 | return 0; 75 | } 76 | // } Driver Code Ends -------------------------------------------------------------------------------- /Microsoft/Prerequisite_Tasks.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution { 7 | public: 8 | 9 | bool completeTask(int tar, vector> & tasks, vector & state) 10 | { 11 | if(state[tar] == 2) { 12 | return true; 13 | } 14 | 15 | else if(state[tar] == 1) { 16 | return false; 17 | } 18 | 19 | state[tar] = 1; // visited 20 | for(auto task: tasks[tar]) 21 | { 22 | bool done = completeTask(task, tasks, state); 23 | if(!done) { 24 | return false; 25 | } 26 | } 27 | state[tar] = 2; // completed 28 | return true; 29 | } 30 | 31 | 32 | bool isPossible(int N, vector >& prerequisites) 33 | { 34 | vector> tasks(N) ; 35 | vector state(N,0) ; 36 | 37 | for(auto pair: prerequisites) 38 | { 39 | tasks[pair.first].push_back(pair.second); 40 | } 41 | 42 | for(int i = 0; i < N; ++i) 43 | { 44 | bool done = completeTask(i, tasks, state); 45 | if(!done) { 46 | return false; 47 | } 48 | } 49 | 50 | return true; 51 | } 52 | }; 53 | 54 | 55 | 56 | 57 | // { Driver Code Starts. 58 | int main() 59 | { 60 | int tc; 61 | cin >> tc; 62 | while(tc--) 63 | { 64 | int N, P; 65 | vector > prerequisites; 66 | cin >> N; 67 | cin >> P; 68 | for (int i = 0; i < P; ++i) { 69 | int x, y; 70 | cin >> x >> y; 71 | prerequisites.push_back(make_pair(x, y)); 72 | } 73 | // string s; 74 | // cin>>s; 75 | Solution ob; 76 | if (ob.isPossible(N, prerequisites)) 77 | cout << "Yes"; 78 | else 79 | cout << "No"; 80 | cout << endl; 81 | } 82 | return 0; 83 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Intuit/15. Pacific Atlantic Water Flow.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | // ?? leetcode 417 4 | 5 | void solve(vector>& matrix , int i , int j , int prev , 6 | vector>& ocean) 7 | { 8 | if(i<0 || i>= matrix.size() || j<0 || j>=matrix[0].size()) 9 | { 10 | return ; 11 | } 12 | if(ocean[i][j] == 1) // no need for dfs 13 | return ; 14 | if(matrix[i][j] < prev) // no need for dfs 15 | return ; 16 | 17 | ocean[i][j]=1 ; 18 | 19 | solve(matrix,i+1,j,matrix[i][j],ocean) ; 20 | solve(matrix,i-1,j,matrix[i][j],ocean) ; 21 | solve(matrix,i,j+1,matrix[i][j],ocean) ; 22 | solve(matrix,i,j-1,matrix[i][j],ocean) ; 23 | 24 | } 25 | 26 | 27 | vector> pacificAtlantic(vector>& matrix) { 28 | vector> ans ; 29 | int n = matrix.size() , m = matrix[0].size(); 30 | if(n<1) return ans ; 31 | 32 | 33 | vector> pacific(n, vector (m,0)) ; 34 | vector> atlantic(n , vector(m,0)) ; 35 | 36 | for(int col =0 ; col< m ; col++) 37 | { 38 | solve(matrix,0,col,INT_MIN , pacific) ; 39 | solve(matrix,n-1 , col, INT_MIN , atlantic) ; 40 | } 41 | 42 | 43 | for(int row =0 ; row< n; row++) 44 | { 45 | solve(matrix,row,0,INT_MIN ,pacific) ; 46 | solve(matrix,row, m -1, INT_MIN ,atlantic) ; 47 | } 48 | 49 | 50 | for(int i=0;i v(2) ; 56 | v[0]=i ; 57 | v[1]=j ; 58 | ans.push_back(v) ; 59 | } 60 | } 61 | } 62 | 63 | return ans ; 64 | } 65 | }; -------------------------------------------------------------------------------- /Intuit/8. Find in the mountain array .cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * // This is the MountainArray's API interface. 3 | * // You should not implement it, or speculate about its implementation 4 | * class MountainArray { 5 | * public: 6 | * int get(int index); 7 | * int length(); 8 | * }; 9 | */ 10 | 11 | class Solution { 12 | public: 13 | int findInMountainArray(int target, MountainArray &Arr) 14 | { 15 | int left = 0 ; 16 | int right = Arr.length() - 1; 17 | // Find the peak index 18 | while (left < right) 19 | { 20 | int mid = left + (right - left) / 2; 21 | if (Arr.get(mid) < Arr.get(mid + 1)) 22 | { 23 | left = mid + 1; 24 | } 25 | else 26 | { 27 | right = mid; 28 | } 29 | } 30 | 31 | 32 | int peak = left; 33 | // Binary search on increasing subarray 34 | left = 0; 35 | right = peak; 36 | while (left <= right) 37 | { 38 | int mid = left + (right - left) / 2; 39 | if (Arr.get(mid) < target) 40 | { 41 | left = mid + 1; 42 | } 43 | else if (Arr.get(mid) > target) 44 | { 45 | right = mid - 1; 46 | } 47 | else 48 | { 49 | return mid; 50 | } 51 | } 52 | 53 | // Binary search on decreasing subarray 54 | left = peak; 55 | right = Arr.length() - 1; 56 | while (left <= right) 57 | { 58 | int mid = left + (right - left) / 2; 59 | if (Arr.get(mid) < target) 60 | { 61 | right = mid - 1; 62 | } 63 | else if (Arr.get(mid) > target) 64 | { 65 | left = mid + 1; 66 | } 67 | else 68 | { 69 | return mid; 70 | } 71 | } 72 | 73 | 74 | return -1; 75 | } 76 | }; -------------------------------------------------------------------------------- /Microsoft/Spirally traversing a matrix.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution 7 | { 8 | public: 9 | //Function to return a list of integers denoting spiral traversal of matrix. 10 | vector spirallyTraverse(vector > mat, int r, int c) 11 | { 12 | // SDE sheet ka sawaal h 13 | int top =0 , left =0 ; 14 | int bottom = r-1 ; 15 | int right = c-1 ; 16 | vector vec ; 17 | 18 | // 4 cond 19 | while(top <= bottom && left <=right) 20 | { 21 | 22 | // first 23 | for(int i=left ; i<=right ; i++) { 24 | vec.push_back(mat[top][i]) ; 25 | } 26 | top ++ ; 27 | 28 | // second 29 | for(int i=top ; i<= bottom ; i++) { 30 | vec.push_back(mat[i][right]) ; 31 | } 32 | right -- ; 33 | 34 | // third 35 | if(top<=bottom) { 36 | for(int i = right ; i>= left; i--) { 37 | vec.push_back(mat[bottom][i]) ; 38 | } 39 | bottom -- ; 40 | } 41 | // forth 42 | if(left <=right) { 43 | for(int i=bottom ; i>=top; i-- ){ 44 | vec.push_back(mat[i][left]) ; 45 | } 46 | left ++ ; 47 | } 48 | 49 | } 50 | 51 | return vec ; 52 | } 53 | }; 54 | 55 | // { Driver Code Starts. 56 | int main() { 57 | int t; 58 | cin>>t; 59 | 60 | while(t--) 61 | { 62 | int r,c; 63 | cin>>r>>c; 64 | vector > matrix(r); 65 | 66 | for(int i=0; i>matrix[i][j]; 72 | } 73 | } 74 | 75 | Solution ob; 76 | vector result = ob.spirallyTraverse(matrix, r, c); 77 | for (int i = 0; i < result.size(); ++i) 78 | cout< 3 | using namespace std; 4 | #define N 1000 5 | 6 | 7 | // } Driver Code Ends 8 | // you are required to complete this function 9 | // function should print the required range 10 | // function should print the required range 11 | 12 | 13 | class Solution{ 14 | typedef pair> ppi ; 15 | public: 16 | pair findSmallestRange(int arr[][N], int n, int k) 17 | { 18 | // create min heap 19 | // pq --> {val,{row,col}} 20 | priority_queue ,greater> pq; 21 | int maxi =0; 22 | for(int i=0; i>t; 68 | while(t--) 69 | { 70 | int n, k; 71 | cin>>n>>k; 72 | int arr[N][N]; 73 | pair rangee; 74 | for(int i=0; i>arr[i][j]; 77 | Solution obj; 78 | rangee = obj.findSmallestRange(arr, n, k); 79 | cout<GEEKSFORGEEKSGEEKSFORGEEKS -------------------------------------------------------------------------------- /Walmart/10. Shortest subsequence of size 3 .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | 4 | using namespace std; 5 | 6 | bool isSubSequence(vector &v1, vector &v2, int n, int m) { 7 | 8 | if (m == 0) return true; 9 | if (n == 0) return false; 10 | 11 | if (v1[n - 1] == v2[m - 1]) return isSubSequence(v1, v2, n - 1, m - 1); 12 | 13 | return isSubSequence(v1, v2, n - 1, m); 14 | } 15 | 16 | 17 | // } Driver Code Ends 18 | /*The function returns a vector containing the 19 | increasing sub-sequence of length 3 if present 20 | else returns an empty vector */ 21 | class Solution{ 22 | public: 23 | vector find3Numbers(vector arr, int N) { 24 | vector v ; 25 | if(N<3) return {} ; 26 | int prev = arr[0] ; 27 | int curr = -1 ; 28 | int next = -1 ; 29 | for(int i=0;i prev and curr ==-1) curr = arr[i] ; 38 | 39 | else if(arr[i]> prev and arr[i]< curr) curr = arr[i] ; 40 | 41 | else if(arr[i] > curr and curr !=-1 and next ==-1) next = arr[i] ; 42 | 43 | } 44 | 45 | if(next !=-1 and curr !=-1) { 46 | v.push_back(prev) ; 47 | v.push_back(curr) ; 48 | v.push_back(next) ; 49 | } 50 | 51 | 52 | 53 | 54 | 55 | return v ; 56 | } 57 | }; 58 | 59 | // { Driver Code Starts. 60 | 61 | // Driver program to test above function 62 | int main() { 63 | int t; 64 | cin >> t; 65 | while (t--) { 66 | int n; 67 | cin >> n; 68 | vector a(n); 69 | for (int i = 0; i < n; i++) cin >> a[i]; 70 | Solution obj; 71 | auto res = obj.find3Numbers(a, n); 72 | 73 | // wrong format output 74 | if (!res.empty() and res.size() != 3) { 75 | cout << -1 << "\n"; 76 | } 77 | 78 | if (res.empty()) { 79 | cout << 0 << "\n"; 80 | } else if ((res[0] < res[1] and res[1] < res[2]) and 81 | isSubSequence(a, res, n, res.size())) { 82 | cout << 1 << "\n"; 83 | } else { 84 | cout << -1 << "\n"; 85 | } 86 | } 87 | 88 | return 0; 89 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Intuit/10. Construct Quad Tree.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | // Definition for a QuadTree node. 3 | class Node { 4 | public: 5 | bool val; 6 | bool isLeaf; 7 | Node* topLeft; 8 | Node* topRight; 9 | Node* bottomLeft; 10 | Node* bottomRight; 11 | 12 | Node() { 13 | val = false; 14 | isLeaf = false; 15 | topLeft = NULL; 16 | topRight = NULL; 17 | bottomLeft = NULL; 18 | bottomRight = NULL; 19 | } 20 | 21 | Node(bool _val, bool _isLeaf) { 22 | val = _val; 23 | isLeaf = _isLeaf; 24 | topLeft = NULL; 25 | topRight = NULL; 26 | bottomLeft = NULL; 27 | bottomRight = NULL; 28 | } 29 | 30 | Node(bool _val, bool _isLeaf, Node* _topLeft, Node* _topRight, Node* _bottomLeft, Node* _bottomRight) { 31 | val = _val; 32 | isLeaf = _isLeaf; 33 | topLeft = _topLeft; 34 | topRight = _topRight; 35 | bottomLeft = _bottomLeft; 36 | bottomRight = _bottomRight; 37 | } 38 | }; 39 | */ 40 | 41 | class Solution { 42 | public: 43 | 44 | Node * solve(vector>& grid , int rowstart , int rowend ,int colstart , int colend , int factor) 45 | 46 | { 47 | int sum = 0; 48 | for(int i=rowstart ; i topLeft = solve(grid,rowstart,rowstart+factor,colstart,colstart+factor,factor); 73 | 74 | dp->topRight = solve(grid,rowstart,rowstart+factor,colstart+factor,colend,factor); 75 | 76 | dp->bottomLeft = solve(grid,rowstart+factor,rowend,colstart,colstart+factor,factor); 77 | 78 | dp->bottomRight = solve(grid,rowstart+factor,rowend,colstart+factor,colend,factor); 79 | } 80 | return dp ; 81 | } 82 | 83 | 84 | 85 | Node* construct(vector>& grid) { 86 | int n = grid.size() ; 87 | if(n==0) return NULL ; 88 | Node* ans; 89 | ans = solve(grid,0,n,0,n,n) ; 90 | return ans; 91 | } 92 | }; -------------------------------------------------------------------------------- /Intuit/5.find the missing no in the string .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | const int MAX_DIGITS = 5; 5 | 6 | int missingNumber(const string& str); 7 | 8 | int main() 9 | { 10 | int t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | string str; 15 | cin>>str; 16 | cout << missingNumber(str)< 5 | using namespace std; 6 | 7 | 8 | // } Driver Code Ends 9 | //User function template for C++ 10 | 11 | class Solution{ 12 | public: 13 | string nextPalin(string num) { 14 | //complete the function here 15 | int n= num.size(); 16 | if (n <= 3) 17 | { 18 | return "-1"; 19 | } 20 | 21 | // find the index of last digit 22 | // in the 1st half of 'num' 23 | // -1 is done becuse it follow 0 based indexing 24 | int mid = n / 2 - 1; 25 | int i, j; 26 | 27 | // Start from the (mid-1)th digit and 28 | // find the first digit that is 29 | // smaller than the digit next to it. 30 | for (i = mid - 1; i >= 0; i--) 31 | if (num[i] < num[i + 1]) 32 | break; 33 | 34 | // if i<0 then next no cannot be formed 35 | if (i < 0) { 36 | 37 | return "-1"; 38 | } 39 | 40 | // Find the smallest digit on right 41 | // side of ith digit which is just greater 42 | // than num[i] up to index 'mid' 43 | int smallest; 44 | 45 | for (j = mid; j >=0; j--) 46 | { 47 | if (num[j] > num[i]) 48 | { 49 | smallest = j; 50 | break; 51 | } 52 | 53 | } 54 | 55 | 56 | 57 | // swap num[i] with num[smallest] 58 | swap(num[i], num[smallest]); 59 | 60 | 61 | // swapping the nos of second half also 62 | swap(num[n - i - 1], num[n - smallest - 1]); 63 | 64 | // reverse digits in the range (i+1) to mid 65 | reverse(num.begin()+i+1,num.begin()+mid+1); 66 | 67 | // reversing the second half 68 | // if n is even, then reverse digits in the 69 | // range mid+1 to n-i-2 70 | if (n % 2 == 0) 71 | reverse(num.begin()+mid+1,num.begin()+n-i-1); 72 | else// else if n is odd, then reverse digit in the range mid+2 to n-i-2 73 | reverse(num.begin()+mid+2,num.begin()+n-i-1); 74 | 75 | // required next higher palindromic number 76 | return num; 77 | } 78 | }; 79 | 80 | // { Driver Code Starts. 81 | 82 | int main() { 83 | 84 | int t; 85 | cin >> t; 86 | while(t--){ 87 | string s; 88 | cin >> s; 89 | Solution obj; 90 | cout << obj.nextPalin(s) << endl; 91 | } 92 | return 0; 93 | } // } Driver Code Ends 94 | -------------------------------------------------------------------------------- /Intuit/4. Word search .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution { 7 | public: 8 | bool findWord(int i, int j, int index, vector>& board, 9 | string& word, vector>& vis) 10 | { 11 | 12 | if(vis[i][j]) 13 | return false; 14 | if(index == word.size()) 15 | return true; 16 | 17 | vis[i][j] = 1; 18 | 19 | // up 20 | if(i > 0 && word[index] == board[i-1][j]) 21 | { 22 | if(findWord(i-1, j, index + 1, board, word, vis)) { 23 | return true; 24 | } 25 | } 26 | 27 | // down 28 | if(i < board.size()-1 && word[index] == board[i+1][j]) { 29 | if(findWord(i+1, j, index + 1, board, word, vis)) { 30 | return true; 31 | } 32 | } 33 | 34 | // left 35 | if(j > 0 && word[index] == board[i][j-1]) 36 | { 37 | if(findWord(i, j-1, index + 1, board, word, vis)) { 38 | return true; 39 | } 40 | } 41 | 42 | // right 43 | if(j < board[0].size()-1 && word[index] == board[i][j+1]) 44 | { 45 | if(findWord(i, j+1, index + 1, board, word, vis)) { 46 | return true; 47 | } 48 | } 49 | 50 | vis[i][j] = 0; 51 | 52 | return false; 53 | } 54 | 55 | 56 | bool isWordExist(vector>& board, string word) { 57 | int n = board.size(); 58 | int m = board[0].size(); 59 | 60 | vector> vis (n, vector(m, 0)); 61 | 62 | for(int i = 0; i < n; ++i) 63 | { 64 | for(int j = 0; j < m; ++j) 65 | { 66 | if(board[i][j] == word[0] && findWord(i, j, 1, board, word, vis)) { 67 | return true ; 68 | } 69 | 70 | } 71 | } 72 | 73 | return false ; 74 | } 75 | }; 76 | 77 | // { Driver Code Starts. 78 | int main(){ 79 | int tc; 80 | cin >> tc; 81 | while(tc--){ 82 | int n, m; 83 | cin >> n >> m; 84 | vector>board(n, vector(m, '*')); 85 | for(int i = 0; i < n; i++) 86 | for(int j = 0; j < m; j++) 87 | cin >> board[i][j]; 88 | string word; 89 | cin >> word; 90 | Solution obj; 91 | bool ans = obj.isWordExist(board, word); 92 | if(ans) 93 | cout << "1\n"; 94 | else cout << "0\n"; 95 | } 96 | return 0; 97 | } // } Driver Code Ends -------------------------------------------------------------------------------- /Amazon/Delete N nodes after M nodes of a linked list.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | /* A linked list node */ 7 | 8 | 9 | struct Node 10 | { 11 | int data; 12 | struct Node *next; 13 | 14 | Node(int x){ 15 | data = x; 16 | next = NULL; 17 | } 18 | 19 | }; 20 | 21 | struct Node *start = NULL; 22 | 23 | /* Function to print nodes in a given linked list */ 24 | void printList(struct Node *node) 25 | { 26 | while(node != NULL) 27 | { 28 | printf("%d ", node->data); 29 | node = node->next; 30 | } 31 | printf("\n"); 32 | 33 | } 34 | 35 | void insert(int n1) 36 | { 37 | int n,value; 38 | n=n1; 39 | struct Node *temp; 40 | 41 | for(int i=0;i>value; 44 | if(i==0) 45 | { 46 | start = new Node(value); 47 | temp=start; 48 | continue; 49 | } 50 | else 51 | { 52 | temp->next = new Node(value); 53 | temp=temp->next; 54 | } 55 | } 56 | } 57 | 58 | // } Driver Code Ends 59 | /* 60 | delete n nodes after m nodes 61 | The input list will have at least one element 62 | Node is defined as 63 | 64 | struct Node 65 | { 66 | int data; 67 | struct Node *next; 68 | 69 | Node(int x){ 70 | data = x; 71 | next = NULL; 72 | } 73 | 74 | }; 75 | 76 | */ 77 | class Solution 78 | { 79 | public: 80 | void linkdelete(struct Node *head, int M, int N) 81 | { 82 | if(!head) return ; 83 | 84 | Node* curr = head ; 85 | 86 | while(curr) 87 | { 88 | for(int i=1 ; i < M && curr; i++) { 89 | curr = curr -> next ; 90 | } 91 | 92 | 93 | if(!curr){ 94 | return ; 95 | } 96 | 97 | Node* temp = curr ; 98 | 99 | for(int i=0; i<=N && curr ; i++) { 100 | curr = curr-> next ; 101 | } 102 | 103 | temp-> next = curr ; 104 | } 105 | } 106 | }; 107 | 108 | 109 | 110 | // { Driver Code Starts. 111 | int main() 112 | { 113 | int t,n1; 114 | cin>>t; 115 | while (t--) { 116 | cin>>n1; 117 | int m,n; 118 | cin>>m; 119 | cin>>n; 120 | insert(n1); 121 | Solution ob; 122 | ob.linkdelete(start,m,n); 123 | printList(start); 124 | } 125 | 126 | return 0; 127 | } 128 | // } Driver Code Ends -------------------------------------------------------------------------------- /Microsoft/Alien Dictionary.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | // Initial Template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | // User function Template for C++ 9 | 10 | class Solution{ 11 | public: 12 | string topologicalSort(char parent, unordered_map> &G, unordered_set &visited) { 13 | if(visited.count(parent)) return ""; 14 | 15 | visited.insert(parent); 16 | 17 | if(G.count(parent) == 0) return string(1, parent); 18 | 19 | string ans = ""; 20 | for(auto child: G[parent]) { 21 | ans += topologicalSort(child, G, visited); 22 | } 23 | 24 | ans += parent; 25 | 26 | return ans; 27 | } 28 | 29 | string findOrder(string dict[], int N, int K) { 30 | 31 | unordered_map> G; 32 | 33 | // build graph 34 | for(int i = 1; i < N; ++i) { 35 | int j = 0; 36 | int limit = min(dict[i-1].size(), dict[i].size()); 37 | 38 | while(j < limit && dict[i-1][j] == dict[i][j]) ++j; 39 | 40 | if(j < limit) G[dict[i-1][j]].push_back(dict[i][j]); 41 | } 42 | 43 | unordered_set visited; 44 | string ans_rev = ""; 45 | 46 | for(auto node: G) { 47 | if(visited.count(node.first)) continue; 48 | ans_rev += topologicalSort(node.first, G, visited); 49 | } 50 | 51 | reverse(ans_rev.begin(), ans_rev.end()); 52 | 53 | return ans_rev; 54 | } 55 | }; 56 | 57 | // { Driver Code Starts. 58 | string order; 59 | bool f(string a, string b) { 60 | int p1 = 0; 61 | int p2 = 0; 62 | for (int i = 0; i < min(a.size(), b.size()) and p1 == p2; i++) { 63 | p1 = order.find(a[i]); 64 | p2 = order.find(b[i]); 65 | // cout<> t; 77 | while (t--) { 78 | int N, K; 79 | cin >> N >> K; 80 | string dict[N]; 81 | for (int i = 0; i < N; i++) cin >> dict[i]; 82 | 83 | Solution obj; 84 | string ans = obj.findOrder(dict, N, K); 85 | order = ""; 86 | for (int i = 0; i < ans.size(); i++) order += ans[i]; 87 | 88 | string temp[N]; 89 | std::copy(dict, dict + N, temp); 90 | sort(temp, temp + N, f); 91 | 92 | bool f = true; 93 | for (int i = 0; i < N; i++) 94 | if (dict[i] != temp[i]) f = false; 95 | 96 | if(f)cout << 1; 97 | else cout << 0; 98 | cout << endl; 99 | } 100 | return 0; 101 | } 102 | // } Driver Code Ends -------------------------------------------------------------------------------- /Amazon/Burning_tree.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | //Initial Template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | struct Node { 8 | int data; 9 | Node *left; 10 | Node *right; 11 | 12 | Node(int val) { 13 | data = val; 14 | left = right = NULL; 15 | } 16 | }; 17 | 18 | 19 | Node *buildTree(string str) { 20 | // Corner Case 21 | if (str.length() == 0 || str[0] == 'N') 22 | return NULL; 23 | 24 | // Creating vector of strings from input 25 | // string after spliting by space 26 | vector ip; 27 | 28 | istringstream iss(str); 29 | for (string str; iss >> str;) 30 | ip.push_back(str); 31 | 32 | // Create the root of the tree 33 | Node *root = new Node(stoi(ip[0])); 34 | 35 | // Push the root to the queue 36 | queue queue; 37 | queue.push(root); 38 | 39 | // Starting from the second element 40 | int i = 1; 41 | while (!queue.empty() && i < ip.size()) { 42 | 43 | // Get and remove the front of the queue 44 | Node *currNode = queue.front(); 45 | queue.pop(); 46 | 47 | // Get the current Node's value from the string 48 | string currVal = ip[i]; 49 | 50 | // If the left child is not null 51 | if (currVal != "N") { 52 | 53 | // Create the left child for the current Node 54 | currNode->left = new Node(stoi(currVal)); 55 | 56 | // Push it to the queue 57 | queue.push(currNode->left); 58 | } 59 | 60 | // For the right child 61 | i++; 62 | if (i >= ip.size()) 63 | break; 64 | currVal = ip[i]; 65 | 66 | // If the right child is not null 67 | if (currVal != "N") { 68 | 69 | // Create the right child for the current Node 70 | currNode->right = new Node(stoi(currVal)); 71 | 72 | // Push it to the queue 73 | queue.push(currNode->right); 74 | } 75 | i++; 76 | } 77 | 78 | return root; 79 | } 80 | 81 | 82 | 83 | class Solution { 84 | public: 85 | int helper(Node* root , int target , int & t) 86 | { 87 | if(root==NULL) 88 | return 0; 89 | int le = helper(root-> left ,target ,t) ; 90 | int ri = helper(root-> right , target ,t) ; 91 | 92 | if(root-> data == target) 93 | { 94 | t = max(t, max(le, ri)) ; 95 | return -1 ; 96 | } 97 | if(le <0){ 98 | t = max(t , ri-le) ; 99 | return le-1 ; 100 | } 101 | if(ri <0){ 102 | t = max(t , -ri+le) ; 103 | return ri-1 ; 104 | } 105 | 106 | return max(le,ri)+1 ; 107 | } 108 | 109 | int minTime(Node* root, int target) 110 | { 111 | int T =0 ; 112 | helper(root,target,T) ; 113 | return T ; 114 | } 115 | }; 116 | 117 | // { Driver Code Starts. 118 | 119 | int main() 120 | { 121 | int tc; 122 | scanf("%d ", &tc); 123 | while (tc--) 124 | { 125 | string treeString; 126 | getline(cin, treeString); 127 | // cout<>target; 130 | // cout< 4 | using namespace std; 5 | 6 | 7 | 8 | class TrieNode 9 | { 10 | public: 11 | 12 | TrieNode* child[26]; 13 | char value; 14 | int ends, depth; 15 | 16 | TrieNode(char letter, int d) 17 | { 18 | value = letter; 19 | ends = 0; 20 | depth = d; 21 | 22 | for(int i = 0; i < 26; ++i) { 23 | child[i] = NULL; 24 | } 25 | } 26 | 27 | 28 | }; 29 | 30 | class Trie { 31 | public: 32 | 33 | TrieNode* root; 34 | 35 | Trie() { 36 | root = new TrieNode('/', 0); 37 | } 38 | 39 | void insert(string& word) { 40 | TrieNode* node = root; 41 | 42 | for(int i = 0; i < word.size(); ++i) { 43 | int index = word[i] - 'a'; 44 | 45 | if(node->child[index] == NULL) 46 | node->child[index] = new TrieNode(word[i], i + 1); 47 | 48 | node = node->child[index]; 49 | } 50 | 51 | node->ends += 1; 52 | } 53 | 54 | 55 | 56 | vector wordsWithPrefix(string prefix) { 57 | TrieNode* node = root; 58 | vector results; 59 | 60 | int N = prefix.length(); 61 | for(int i = 0; i < N; ++i) { 62 | node = node->child[prefix[i] - 'a']; 63 | if(node == NULL) return results; 64 | } 65 | TrieNode* prefix_end = node; 66 | 67 | stack nodes; 68 | nodes.push(node); 69 | string stream = ""; 70 | 71 | while(!nodes.empty()) { 72 | node = nodes.top(); 73 | nodes.pop(); 74 | 75 | if(stream.size() > node->depth - prefix_end->depth) { 76 | stream = stream.substr(0, node->depth - prefix_end->depth); 77 | } 78 | 79 | stream += node->value; 80 | for(int i = 25; i >= 0; --i) { 81 | if(node->child[i] != NULL) { 82 | nodes.push(node->child[i]); 83 | } 84 | } 85 | 86 | if(node->ends) { 87 | results.push_back(prefix + stream.substr(1)); 88 | } 89 | } 90 | 91 | return results; 92 | } 93 | }; 94 | 95 | 96 | 97 | class Solution{ 98 | public: 99 | vector> displayContacts(int n, string contact[], string s) 100 | { 101 | Trie* dict = new Trie(); 102 | for(int i = 0; i < n; ++i) 103 | { 104 | dict->insert(contact[i]); 105 | } 106 | 107 | vector> ans(s.size()); 108 | 109 | for(int i = 0; i < s.size(); ++i) 110 | { 111 | vector res = dict->wordsWithPrefix(s.substr(0, i + 1)); 112 | if(res.empty()) 113 | { 114 | ans[i] = {"0"}; 115 | } 116 | else { 117 | ans[i] = res; 118 | } 119 | } 120 | return ans; 121 | } 122 | }; 123 | 124 | // { Driver Code Starts. 125 | 126 | int main(){ 127 | int t; 128 | cin>>t; 129 | while(t--){ 130 | int n; 131 | cin>>n; 132 | string contact[n], s; 133 | for(int i = 0;i < n;i++) 134 | cin>>contact[i]; 135 | cin>>s; 136 | 137 | Solution ob; 138 | vector> ans = ob.displayContacts(n, contact, s); 139 | for(int i = 0;i < s.size();i++){ 140 | for(auto u: ans[i]) 141 | cout< 4 | using namespace std; 5 | 6 | // Tree Node 7 | struct Node 8 | { 9 | int data; 10 | Node* left; 11 | Node* right; 12 | }; 13 | 14 | // Utility function to create a new Tree Node 15 | Node* newNode(int val) 16 | { 17 | Node* temp = new Node; 18 | temp->data = val; 19 | temp->left = NULL; 20 | temp->right = NULL; 21 | 22 | return temp; 23 | } 24 | 25 | // Function to Build Tree 26 | Node* buildTree(string str) 27 | { 28 | // Corner Case 29 | if(str.length() == 0 || str[0] == 'N') 30 | return NULL; 31 | 32 | // Creating vector of strings from input 33 | // string after spliting by space 34 | vector ip; 35 | 36 | istringstream iss(str); 37 | for(string str; iss >> str; ) 38 | ip.push_back(str); 39 | 40 | // Create the root of the tree 41 | Node* root = newNode(stoi(ip[0])); 42 | 43 | // Push the root to the queue 44 | queue queue; 45 | queue.push(root); 46 | 47 | // Starting from the second element 48 | int i = 1; 49 | while(!queue.empty() && i < ip.size()) { 50 | 51 | // Get and remove the front of the queue 52 | Node* currNode = queue.front(); 53 | queue.pop(); 54 | 55 | // Get the current node's value from the string 56 | string currVal = ip[i]; 57 | 58 | // If the left child is not null 59 | if(currVal != "N") { 60 | 61 | // Create the left child for the current node 62 | currNode->left = newNode(stoi(currVal)); 63 | 64 | // Push it to the queue 65 | queue.push(currNode->left); 66 | } 67 | 68 | // For the right child 69 | i++; 70 | if(i >= ip.size()) 71 | break; 72 | currVal = ip[i]; 73 | 74 | // If the right child is not null 75 | if(currVal != "N") { 76 | 77 | // Create the right child for the current node 78 | currNode->right = newNode(stoi(currVal)); 79 | 80 | // Push it to the queue 81 | queue.push(currNode->right); 82 | } 83 | i++; 84 | } 85 | 86 | return root; 87 | } 88 | 89 | // Your are required to complete this function 90 | int countSubtreesWithSumX(Node* root, int x); 91 | 92 | int main() 93 | { 94 | int t; 95 | cin>>t; 96 | getchar(); 97 | while (t--) 98 | { 99 | string s; 100 | getline(cin,s); 101 | Node* root = buildTree(s); 102 | 103 | int x; 104 | cin>>x; 105 | getchar(); 106 | cout << countSubtreesWithSumX(root, x)< subtreeSum(Node* root, int x) { 125 | 126 | if(root == NULL) return {0, 0}; 127 | 128 | int count = 0; 129 | 130 | pair left = subtreeSum(root->left, x); 131 | pair right = subtreeSum(root->right, x); 132 | 133 | count += left.first; 134 | count += right.first; 135 | 136 | int sum = left.second + right.second + root->data; 137 | 138 | if(sum == x) { 139 | ++count; 140 | } 141 | 142 | return {count, sum}; 143 | } 144 | //Function to count number of subtrees having sum equal to given sum. 145 | int countSubtreesWithSumX(Node* root, int X) 146 | { 147 | pair p = subtreeSum(root, X); 148 | return p.first; 149 | } 150 | -------------------------------------------------------------------------------- /Walmart/9. Transform to Sum Tree .cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | struct Node 6 | { 7 | int data; 8 | struct Node *left; 9 | struct Node *right; 10 | }; 11 | // Utility function to create a new Tree Node 12 | Node* newNode(int val) 13 | { 14 | Node* temp = new Node; 15 | temp->data = val; 16 | temp->left = NULL; 17 | temp->right = NULL; 18 | 19 | return temp; 20 | } 21 | // Function to Build Tree 22 | Node* buildTree(string str) 23 | { 24 | // Corner Case 25 | if(str.length() == 0 || str[0] == 'N') 26 | return NULL; 27 | 28 | // Creating vector of strings from input 29 | // string after spliting by space 30 | vector ip; 31 | 32 | istringstream iss(str); 33 | for(string str; iss >> str; ) 34 | ip.push_back(str); 35 | 36 | // Create the root of the tree 37 | Node* root = newNode(stoi(ip[0])); 38 | 39 | // Push the root to the queue 40 | queue queue; 41 | queue.push(root); 42 | 43 | // Starting from the second element 44 | int i = 1; 45 | while(!queue.empty() && i < ip.size()) { 46 | 47 | // Get and remove the front of the queue 48 | Node* currNode = queue.front(); 49 | queue.pop(); 50 | 51 | // Get the current node's value from the string 52 | string currVal = ip[i]; 53 | 54 | // If the left child is not null 55 | if(currVal != "N") { 56 | 57 | // Create the left child for the current node 58 | currNode->left = newNode(stoi(currVal)); 59 | 60 | // Push it to the queue 61 | queue.push(currNode->left); 62 | } 63 | 64 | // For the right child 65 | i++; 66 | if(i >= ip.size()) 67 | break; 68 | currVal = ip[i]; 69 | 70 | // If the right child is not null 71 | if(currVal != "N") { 72 | 73 | // Create the right child for the current node 74 | currNode->right = newNode(stoi(currVal)); 75 | 76 | // Push it to the queue 77 | queue.push(currNode->right); 78 | } 79 | i++; 80 | } 81 | 82 | return root; 83 | } 84 | void inorder(Node * node) 85 | { 86 | if(node==NULL) 87 | return; 88 | 89 | inorder(node->left); 90 | cout<data<<" "; 91 | inorder(node->right); 92 | } 93 | 94 | 95 | // } Driver Code Ends 96 | //User function template for C++ 97 | 98 | /* A binary tree node 99 | struct Node 100 | { 101 | int data; 102 | Node* left, * right; 103 | }; */ 104 | 105 | class Solution { 106 | public: 107 | 108 | // Convert a given tree to a tree where every node contains sum of values of 109 | // nodes in left and right subtrees in the original tree 110 | void toSumTree(Node *root) 111 | { 112 | solve(root) ; 113 | } 114 | 115 | // tc -> O(n) 116 | // sc-> O(H) 117 | 118 | int solve(Node * root) 119 | { 120 | if(root==NULL) return 0 ; 121 | 122 | int left = solve(root-> left) ; 123 | int right = solve(root-> right) ; 124 | int val = root-> data ; 125 | 126 | root-> data = left + right ; 127 | 128 | return left + right + val ; 129 | 130 | } 131 | }; 132 | 133 | // { Driver Code Starts. 134 | 135 | int main() 136 | { 137 | 138 | int t; 139 | scanf("%d ",&t); 140 | while(t--) 141 | { 142 | string s; 143 | getline(cin,s); 144 | Node* root = buildTree(s); 145 | Solution ob; 146 | ob.toSumTree(root); 147 | inorder(root); 148 | cout< 3 | using namespace std; 4 | 5 | // Tree Node 6 | struct Node 7 | { 8 | int data; 9 | Node* left; 10 | Node* right; 11 | Node* nextRight; 12 | }; 13 | 14 | // Utility function to create a new Tree Node 15 | Node* newNode(int val) 16 | { 17 | Node* temp = new Node; 18 | temp->data = val; 19 | temp->left = NULL; 20 | temp->right = NULL; 21 | temp->nextRight = NULL; 22 | 23 | return temp; 24 | } 25 | 26 | // Function to Build Tree 27 | Node* buildTree(string str) 28 | { 29 | // Corner Case 30 | if(str.length() == 0 || str[0] == 'N') 31 | return NULL; 32 | 33 | // Creating vector of strings from input 34 | // string after spliting by space 35 | vector ip; 36 | 37 | istringstream iss(str); 38 | for(string str; iss >> str; ) 39 | ip.push_back(str); 40 | 41 | // Create the root of the tree 42 | Node* root = newNode(stoi(ip[0])); 43 | 44 | // Push the root to the queue 45 | queue queue; 46 | queue.push(root); 47 | 48 | // Starting from the second element 49 | int i = 1; 50 | while(!queue.empty() && i < ip.size()) { 51 | 52 | // Get and remove the front of the queue 53 | Node* currNode = queue.front(); 54 | queue.pop(); 55 | 56 | // Get the current node's value from the string 57 | string currVal = ip[i]; 58 | 59 | // If the left child is not null 60 | if(currVal != "N") { 61 | 62 | // Create the left child for the current node 63 | currNode->left = newNode(stoi(currVal)); 64 | 65 | // Push it to the queue 66 | queue.push(currNode->left); 67 | } 68 | 69 | // For the right child 70 | i++; 71 | if(i >= ip.size()) 72 | break; 73 | currVal = ip[i]; 74 | 75 | // If the right child is not null 76 | if(currVal != "N") { 77 | 78 | // Create the right child for the current node 79 | currNode->right = newNode(stoi(currVal)); 80 | 81 | // Push it to the queue 82 | queue.push(currNode->right); 83 | } 84 | i++; 85 | } 86 | 87 | return root; 88 | } 89 | 90 | void connect(struct Node *p); 91 | 92 | /* Helper function that allocates a new node with the 93 | given data and NULL left and right pointers. */ 94 | 95 | 96 | void printSpecial(Node *root) 97 | { 98 | if (root == NULL) 99 | return; 100 | 101 | Node* next_root=NULL; 102 | 103 | while (root != NULL) 104 | { 105 | cout<< root->data<<" "; 106 | 107 | if( root->left && (!next_root) ) 108 | next_root = root->left; 109 | else if( root->right && (!next_root) ) 110 | next_root = root->right; 111 | 112 | root = root->nextRight; 113 | } 114 | 115 | printSpecial(next_root); 116 | } 117 | 118 | void inorder(Node *root) 119 | { 120 | if (root == NULL) 121 | return; 122 | inorder(root->left); 123 | cout << root->data << " "; 124 | inorder(root->right); 125 | } 126 | 127 | 128 | // } Driver Code Ends 129 | /* struct Node 130 | { 131 | int data; 132 | Node *left, *right; 133 | Node *nextRight; // This has garbage value in input trees 134 | }; */ 135 | 136 | 137 | class Solution 138 | { 139 | public: 140 | //Function to connect nodes at same level. 141 | void connect(Node *root) 142 | { 143 | // Your Code Here 144 | 145 | // straight forward BFS 146 | 147 | queue q; 148 | q.push(root); 149 | q.push(NULL); 150 | 151 | while(!q.empty()) 152 | { 153 | Node* root = q.front(); 154 | q.pop(); 155 | 156 | if(root == NULL) { 157 | if(!q.empty()) { 158 | q.push(NULL); 159 | } 160 | continue; 161 | } 162 | 163 | root->nextRight = q.front(); 164 | 165 | if(root->left) 166 | q.push(root->left); 167 | if(root->right) 168 | q.push(root->right); 169 | } 170 | } 171 | 172 | }; 173 | 174 | 175 | 176 | 177 | // { Driver Code Starts. 178 | 179 | 180 | /* Driver program to test size function*/ 181 | int main() 182 | { 183 | int t; 184 | scanf("%d\n", &t); 185 | while (t--) 186 | { 187 | string s; 188 | getline(cin, s); 189 | Node* root = buildTree(s); 190 | 191 | Solution obj; 192 | obj.connect(root); 193 | printSpecial(root); 194 | cout< 3 | 4 | using namespace std; 5 | 6 | // Tree Node 7 | struct Node { 8 | int data; 9 | Node *left; 10 | Node *right; 11 | 12 | Node(int val) { 13 | data = val; 14 | left = right = NULL; 15 | } 16 | }; 17 | 18 | // Function to Build Tree 19 | Node *buildTree(string str) { 20 | // Corner Case 21 | if (str.length() == 0 || str[0] == 'N') 22 | return NULL; 23 | 24 | // Creating vector of strings from input 25 | // string after spliting by space 26 | vector ip; 27 | 28 | istringstream iss(str); 29 | for (string str; iss >> str;) 30 | ip.push_back(str); 31 | 32 | // Create the root of the tree 33 | Node *root = new Node(stoi(ip[0])); 34 | 35 | // Push the root to the queue 36 | queue queue; 37 | queue.push(root); 38 | 39 | // Starting from the second element 40 | int i = 1; 41 | while (!queue.empty() && i < ip.size()) { 42 | 43 | // Get and remove the front of the queue 44 | Node *currNode = queue.front(); 45 | queue.pop(); 46 | 47 | // Get the current Node's value from the string 48 | string currVal = ip[i]; 49 | 50 | // If the left child is not null 51 | if (currVal != "N") { 52 | 53 | // Create the left child for the current Node 54 | currNode->left = new Node(stoi(currVal)); 55 | 56 | // Push it to the queue 57 | queue.push(currNode->left); 58 | } 59 | 60 | // For the right child 61 | i++; 62 | if (i >= ip.size()) 63 | break; 64 | currVal = ip[i]; 65 | 66 | // If the right child is not null 67 | if (currVal != "N") { 68 | 69 | // Create the right child for the current Node 70 | currNode->right = new Node(stoi(currVal)); 71 | 72 | // Push it to the queue 73 | queue.push(currNode->right); 74 | } 75 | i++; 76 | } 77 | 78 | return root; 79 | } 80 | 81 | 82 | // } Driver Code Ends 83 | /* A binary tree node has data, pointer to left child 84 | and a pointer to right child 85 | struct Node 86 | { 87 | int data; 88 | Node* left; 89 | Node* right; 90 | }; */ 91 | 92 | 93 | class Solution 94 | { 95 | public: 96 | //Function to serialize a tree and return a list containing nodes of tree. 97 | vector serialize(Node *root) 98 | { 99 | //Your code here 100 | if(root == NULL) 101 | { 102 | return {}; 103 | } 104 | 105 | vector left = serialize(root->left); 106 | vector right = serialize(root->right); 107 | 108 | vector ans; 109 | 110 | // preallocate memory 111 | ans.reserve(left.size() + right.size() + 1); 112 | ans.insert(ans.end(), left.begin(), left.end()); 113 | ans.push_back(root->data); 114 | ans.insert(ans.end(), right.begin(), right.end()); 115 | 116 | return ans; 117 | } 118 | 119 | //Function to deserialize a list and construct the tree. 120 | Node * deSerialize(vector &A) 121 | { 122 | int N = A.size(); 123 | 124 | if(N == 1) { 125 | Node* root = new Node(A[0]); 126 | return root; 127 | } 128 | if(N == 2) { 129 | Node* left = new Node(A[0]); 130 | Node* root = new Node(A[1]); 131 | root->left = left; 132 | return root; 133 | } 134 | 135 | Node* left = new Node(A[0]); 136 | Node* root = new Node(A[1]); 137 | Node* right = new Node(A[2]); 138 | 139 | root->left = left; 140 | root->right = right; 141 | 142 | for(int i = 3; i < N; i += 2) { 143 | Node* new_root = new Node(A[i]); 144 | Node* new_right = i == N-1 ? NULL : new Node(A[i + 1]); 145 | 146 | new_root->left = root; 147 | new_root->right = new_right; 148 | 149 | root = new_root; 150 | } 151 | 152 | return root; 153 | } 154 | 155 | }; 156 | 157 | // { Driver Code Starts. 158 | 159 | void inorder(Node *root) { 160 | if (root == NULL) 161 | return; 162 | inorder(root->left); 163 | cout << root->data << " "; 164 | inorder(root->right); 165 | } 166 | 167 | void _deleteTree(Node* node) 168 | { 169 | if (node == NULL) return; 170 | 171 | /* first delete both subtrees */ 172 | _deleteTree(node->left); 173 | _deleteTree(node->right); 174 | 175 | /* then delete the node */ 176 | //cout << "Deleting node: " << node->data << endl; 177 | delete node; 178 | } 179 | 180 | /* Deletes a tree and sets the root as NULL */ 181 | void deleteTree(Node** node_ref) 182 | { 183 | _deleteTree(*node_ref); 184 | *node_ref = NULL; 185 | } 186 | 187 | int main() { 188 | int tc; 189 | scanf("%d ", &tc); 190 | while (tc--) { 191 | string treeString; 192 | getline(cin, treeString); 193 | Node *root = buildTree(treeString); 194 | 195 | Solution serial, deserial; 196 | vector A = serial.serialize(root); 197 | deleteTree(&root); 198 | Node *getRoot = deserial.deSerialize(A); 199 | inorder(getRoot); 200 | cout << "\n"; 201 | 202 | } 203 | 204 | 205 | return 0; 206 | } // } Driver Code Ends -------------------------------------------------------------------------------- /TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Problem Sets 4 | 5 |
6 | Goldman Sachs (15/15) 7 | 8 | Sr | [Problems](./goldman-sachs/README.md) | TryIt | Status 9 | ----|---------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|--------- 10 | 1 | [Print Anagrams Together](./goldman-sachs/print-anagrams-together.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/print-anagrams-together/1/#) | ✅ 11 | 2 | [Overlapping Rectangles](./goldman-sachs/overlapping-rectangles1924.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/overlapping-rectangles1924/1/) | ✅ 12 | 3 | [Count the subarrays having product less than k](./goldman-sachs/count-the-subarrays-having-product-less-than-k1708.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/count-the-subarrays-having-product-less-than-k1708/1/) | ✅ 13 | 4 | [Run Length Encoding](./goldman-sachs/run-length-encoding.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/run-length-encoding/1/) | ✅ 14 | 5 | [Ugly Number](./goldman-sachs/ugly-numbers2254.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/ugly-numbers2254/1/) | ✅ 15 | 6 | [Greatest Common Divisor of Strings](./goldman-sachs/greatest-common-divisor-of-strings.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/greatest-common-divisor-of-strings/) | ✅ 16 | 7 | [Find the position of M-th item](./goldman-sachs/find-the-position-of-m-th-item1723.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/find-the-position-of-m-th-item1723/1#) | ✅ 17 | 8 | [Total Decoding Messages](./goldman-sachs/total-decoding-messages1235.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/total-decoding-messages1235/1/) | ✅ 18 | 9 | [Number following a pattern](./goldman-sachs/number-following-a-pattern3126.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/number-following-a-pattern3126/1#) | ✅ 19 | 10 | [Max 10 numbers in a list having 10M entries](./goldman-sachs/k-largest-elements3736.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/k-largest-elements3736/1) | ✅ 20 | 11 | [Find Missing And Repeating](./goldman-sachs/find-missing-and-repeating2512.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/find-missing-and-repeating2512/1/#) | ✅ 21 | 12 | [Squares in N*N Chessboard](./goldman-sachs/squares-in-nn-chessboard1801.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/squares-in-nn-chessboard1801/1) | ✅ 22 | 13 | [Decode the string](./goldman-sachs/decode-the-string2444.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/decode-the-string2444/1) | ✅ 23 | 14 | [Minimum Size Subarray Sum](./goldman-sachs/minimum-size-subarray-sum.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/minimum-size-subarray-sum/) | ✅ 24 | 15 | [Array Pair Sum Divisibility Problem](./goldman-sachs/array-pair-sum-divisibility-problem3257.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/array-pair-sum-divisibility-problem3257/1#) | ✅ 25 | 26 |
27 | 28 |
29 | Amazon (15/15) 30 | 31 | Sr | [Problems](./amazon/README.md) | TryIt | Status 32 | ----|---------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|--------- 33 | 1 | [Maximum Profit](./amazon/maximum-profit.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/maximum-profit4657/1) | ✅ 34 | 2 | [Longest Mountain in Array](./amazon/longest-mountain-in-array.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/longest-mountain-in-array/) | ✅ 35 | 3 | [IPL 2021 - Match Day 2](./amazon/ipl-2021-match-day-2.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/deee0e8cf9910e7219f663c18d6d640ea0b87f87/1/) | ✅ 36 | 4 | [Brackets in Matrix Chain Multiplication](./brackets-in-matrix-chain-multiplication.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/brackets-in-matrix-chain-multiplication1024/1/) | ✅ 37 | 5 | [Phone directory](./amazon/phone-directory.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/phone-directory4628/1/) | ✅ 38 | 6 | [Maximum of all subarrays of size k](./amazon/maximum-of-all-subarrays-of-size.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/maximum-of-all-subarrays-of-size-k3101/1) | ✅ 39 | 7 | [First non-repeating character in a stream](./amazon/first-non-repeating-character-in-a-stream.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/first-non-repeating-character-in-a-stream1216/1) | ✅ 40 | 8 | [Count ways to N'th Stair(Order does not matter)](./amazon/count-ways-to-nth-stairorder-does-not-matter.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/count-ways-to-nth-stairorder-does-not-matter1322/1/) | ✅ 41 | 9 | [Is Sudoku Valid](./amazon/is-sudoku-valid.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/is-sudoku-valid4820/1/) | ✅ 42 | 10 | [Nuts and Bolts Problem](./amazon/nuts-and-bolts-problem.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/nuts-and-bolts-problem0431/1) | ✅ 43 | 11 | [Serialize and Deserialize a Binary Tree](./amazon/serialize-and-deserialize-a-binary-tree.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/serialize-and-deserialize-a-binary-tree/1) | ✅ 44 | 12 | [Column name from a given column number](./amazon/column-name-from-a-given-column-number.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/column-name-from-a-given-column-number4244/1/) | ✅ 45 | 13 | [Rotting Oranges](./amazon/rotting-oranges.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/rotting-oranges/) | ✅ 46 | 14 | [Burning Tree](./amazon/burning-tree.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/burning-tree/1/) | ✅ 47 | 15 | [Delete N nodes after M nodes of a linked list](./amazon/delete-n-nodes-after-m-nodes-of-a-linked-list.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/delete-n-nodes-after-m-nodes-of-a-linked-list/1/) | ✅ 48 | 49 |
50 | 51 |
52 | Microsoft (15/15) 53 | 54 | Sr | [Problems](./microsoft/README.md) | TryIt | Status 55 | ----|--------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------------|--------- 56 | 1 | [Minimum sum partition](./microsoft/minimum-sum-partition.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/minimum-sum-partition3317/1/) | ✅ 57 | 2 | [Prerequisite Tasks](./microsoft/prerequisite-tasks.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/prerequisite-tasks/1/) | ✅ 58 | 3 | [Rotate by 90 degree](./microsoft/rotate-by-90-degree.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/rotate-by-90-degree0356/1/) | ✅ 59 | 4 | [Spirally traversing a matrix](./microsoft/spirally-traversing-a-matrix.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/spirally-traversing-a-matrix-1587115621/1/) | ✅ 60 | 5 | [Stock span problem](./microsoft/stock-span-problem.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/stock-span-problem-1587115621/1) | ✅ 61 | 6 | [Possible Words From Phone Digits](./microsoft/possible-words-from-phone-digits.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/possible-words-from-phone-digits-1587115620/1/) | ✅ 62 | 7 | [Unit Area of largest region of 1's](./microsoft/length-of-largest-region-of-1s.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/length-of-largest-region-of-1s-1587115620/1/) | ✅ 63 | 8 | [Connect Nodes at Same Level](./microsoft/connect-nodes-at-same-level.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/connect-nodes-at-same-level/1/) | ✅ 64 | 9 | [Count Number of SubTrees having given Sum](./microsoft/count-number-of-subtrees-having-given-sum.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/count-number-of-subtrees-having-given-sum/1/) | ✅ 65 | 10 | [Stickler Thief](./microsoft/stickler-theif.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/stickler-theif-1587115621/1/) | ✅ 66 | 11 | [Generate Binary Numbers](./microsoft/generate-binary-numbers.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/generate-binary-numbers-1587115620/1/) | ✅ 67 | 12 | [Find All Four Sum Numbers](./microsoft/find-all-four-sum-numbers.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/find-all-four-sum-numbers1732/1) | ✅ 68 | 13 | [Bridge edge in a graph](./microsoft/bridge-edge-in-graph.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/bridge-edge-in-graph/1) | ✅ 69 | 14 | [Minimum steps to destination](./microsoft/minimum-steps-to-destination.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/minimum-number-of-steps-to-reach-a-given-number5234/1/) | ✅ 70 | 15 | [Alien Dictionary](./microsoft/alien-dictionary.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/alien-dictionary/1/) | ✅ 71 | 72 |
73 | 74 |
75 | Adobe (15/15) 76 | 77 | Sr | [Problems](./adobe/README.md) | TryIt | Status 78 | ----|-----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------- 79 | 1 | [Subarray with given sum](./adobe/subarray-with-given-sum.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/subarray-with-given-sum-1587115621/1) | ✅ 80 | 2 | [Longest Arithmetic Progression](./adobe/longest-arithmetic-progression.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/longest-arithmetic-progression1019/1/) | ✅ 81 | 3 | [No. of distict Words with k max contiguous vowels](./adobe/kmax-cont-vowels.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/7b9d245852bd8caf8a27d6d3961429f0a2b245f1/1/) | ✅ 82 | 4 | [Partition Equal Subset Sum](./adobe/subset-sum-problem.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/subset-sum-problem2014/1) | ✅ 83 | 5 | [Express as sum of power of natural numbers](./adobe/sum-of-power-of-natural-numbers.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/express-as-sum-of-power-of-natural-numbers5647/1) | ✅ 84 | 6 | [Generate Parentheses](./adobe/generate-parentheses.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/generate-all-possible-parentheses/1/) | ✅ 85 | 7 | Pots of Gold Game | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/pots-of-gold-game/1/) | ✅ 86 | 8 | [Implement Atoi](./adobe/implement-atoi.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/implement-atoi/1/) | ✅ 87 | 9 | [Next higher palindromic number using same digits](./adobe/next-higher-palindromic-number-same-digit.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/next-higher-palindromic-number-using-the-same-set-of-digits5859/1/) | ✅ 88 | 10 | [Winner of an election](./adobe/winner-of-an-election.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/winner-of-an-election-where-votes-are-represented-as-candidate-names-1587115621/1/) | ✅ 89 | 11 | [Amend The Sentence](./adobe/amend-the-sentence.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/amend-the-sentence3235/1) | ✅ 90 | 12 | [Leaders in an array](./adobe/leaders-in-an-array.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/leaders-in-an-array-1587115620/1/) | ✅ 91 | 13 | [Minimum operations to convert array A to B](./adobe/minimum-insertions-to-make-two-arrays-equal.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/minimum-insertions-to-make-two-arrays-equal/1/) | ✅ 92 | 14 | Smallest range in K lists | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/find-smallest-range-containing-elements-from-k-lists/1/) | ✅ 93 | 15 | [Most Recent Library](./adobe/most-recent-library.md) | | ✅ 94 | 95 |
96 | 97 |
98 | Intuit (15/15) 99 | 100 | Sr | Problems | TryIt | Status 101 | ----|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|-------- 102 | 1 | [Minimum sum partition](./intuit/minimum-sum-partition.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/minimum-sum-partition3317/1/) | ✅ 103 | 2 | [Word Search](./intuit/word-search.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/word-search/1/) | ✅ 104 | 3 | [Find the missing no in string](./intuit/missing-no-in-string.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/find-the-missing-no-in-string/1/) | ✅ 105 | 4 | [Largest number in K swaps](./intuit/largest-number-in-k-swaps.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/largest-number-in-k-swaps-1587115620/1) | ✅ 106 | 5 | [Split Array Largest Sum](./intuit/split-array-largest-sum.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/split-array-largest-sum/) | ✅ 107 | 6 | [Find in Mountain Array](./intuit/find-in-mountain-array.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/find-in-mountain-array/) | ✅ 108 | 7 | [Capacity To Ship Packages Within D Days](./intuit/capacity-to-ship-packages-within-d-days.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/) | ✅ 109 | 8 | [Number of Boomerangs](./intuit/number-of-boomerangs.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/number-of-boomerangs/) | ✅ 110 | 9 | [Pacific Atlantic Water Flow](./intuit/pacific-atlantic-water-flow.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/pacific-atlantic-water-flow/) | ✅ 111 | 10 | [Number of Provinces](./intuit/number-of-provinces.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/number-of-provinces/) | ✅ 112 | 11 | Construct Quad Tree | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/construct-quad-tree/) | ✅ 113 | 12 | Course Schedule II | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/course-schedule-ii/) | ✅ 114 | 13 | Minimum Swaps to Arrange a Binary Grid | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid/) | ✅ 115 | 14 | As Far from Land as Possible | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/as-far-from-land-as-possible/) | ✅ 116 | 15 | Koko Eating Bananas | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/koko-eating-bananas/) | ✅ 117 | 118 |
119 | 120 | 121 | 122 | 123 |
124 | Walmart (15/15) 125 | 126 | Sr | Problems | TryIt | Status 127 | ----|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|-------- 128 | 1 | Path with Maximum Probability | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/path-with-maximum-probability/) | ✅ 129 | 2 | Stone Game | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/stone-game/) | ✅ 130 | 3 | Remove Colored Pieces if Both Neighbors are the Same Color | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/) | ✅ 131 | 4 | [Number of Unique Paths](./walmart/number-of-unique-paths.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/number-of-unique-paths5339/1/) | ✅ 132 | 5 | [Transform to Sum Tree](./walmart/transform-to-sum-tree.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/transform-to-sum-tree/1/) | ✅ 133 | 6 | [Power Of Numbers](./walmart/power-of-numbers.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/power-of-numbers-1587115620/1/) | ✅ 134 | 7 | [Sorted subsequence of size 3](./walmart/sorted-subsequence-of-size-3.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/sorted-subsequence-of-size-3/1/) | ✅ 135 | 8 | [Maximum Height Tree](./walmart/maximum-height-tree.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/maximum-height-tree4803/1/) | ✅ 136 | 9 | Guess Number Higher or Lower II | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/guess-number-higher-or-lower-ii/) | ✅ 137 | 10 | Generate Random Point in a Circle | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/generate-random-point-in-a-circle/) | ✅ 138 | 11 | Maximum Performance of a Team | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/maximum-performance-of-a-team/) | ✅ 139 | 12 | Find Array Given Subset Sums | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/find-array-given-subset-sums/) | ✅ 140 | 13 | [Find the Kth Largest Integer in the Array](./walmart/find-the-kth-largest-integer-in-the-array.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/find-the-kth-largest-integer-in-the-array/) | ✅ 141 | 14 | [Largest number in K swaps](./walmart/largest-number-in-k-swaps.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/largest-number-in-k-swaps-1587115620/1/) | ✅ 142 | 15 | Divide Two Integers | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/divide-two-integers/) | ✅ 143 | 144 |
145 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | #RevisewithArsh #6Companies30days #dhindhora #stop #procastination 3 | 4 | #ReviseWithArsh #6Companies30Days Challenge! 5 | 6 | P.S This can be started anytime in the month of January. 7 | 8 | For complete details , go through the video : https://www.youtube.com/watch?v=8ESo_bXhRC4 9 | 10 | 11 | Let’s get started! 12 | 13 | 14 | **Day 1-5 :** 15 | 16 | Company Name : **Goldman Sachs** 17 | 18 | **Day 6-10 :** 19 | 20 | Company Name : **Amazon** 21 | 22 | 23 | **Day 11-15 :** 24 | 25 | Company Name : **Microsoft** 26 | 27 | 28 | **Day 16-20 :** 29 | 30 | Company Name : **Adobe** 31 | 32 | 33 | **Day 21-25 :** 34 | 35 | Company Name : **Intuit** 36 | 37 | 38 | **Day 26-30 :** 39 | 40 | Company Name : **Walmart** 41 | 42 | 43 | 44 |
45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 |
DatesCompany NameLink
01-01-2022 - 05-01-2022Goldman Sachs Check it out
06-01-2022 - 10-01-2022Amazon Check it out
11-01-2022 - 15-01-2022Microsoft Check it out
16-01-2022 - 20-01-2022Adobe Check it out
21-01-2022 - 25-01-2022Intuit Check it out
26-01-2022 - 30-01-2022Walmart Check it out
82 |
83 | 84 | 85 | ...................................................................................................................................................................... 86 | 87 | 88 | **Today, I am up with the challenge! 🚀 Dated : 30-01-2022** 89 | 90 | 91 | ...................................................................................................................................................................... 92 | 93 |
94 | 95 | 96 | ## Problem Sets 97 | 98 |
99 | Goldman Sachs (15/15) 100 | 101 | Sr | [Problems](./goldman-sachs/README.md) | TryIt | Status 102 | ----|---------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|--------- 103 | 1 | [Print Anagrams Together](./goldman-sachs/print-anagrams-together.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/print-anagrams-together/1/#) | ✅ 104 | 2 | [Overlapping Rectangles](./goldman-sachs/overlapping-rectangles1924.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/overlapping-rectangles1924/1/) | ✅ 105 | 3 | [Count the subarrays having product less than k](./goldman-sachs/count-the-subarrays-having-product-less-than-k1708.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/count-the-subarrays-having-product-less-than-k1708/1/) | ✅ 106 | 4 | [Run Length Encoding](./goldman-sachs/run-length-encoding.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/run-length-encoding/1/) | ✅ 107 | 5 | [Ugly Number](./goldman-sachs/ugly-numbers2254.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/ugly-numbers2254/1/) | ✅ 108 | 6 | [Greatest Common Divisor of Strings](./goldman-sachs/greatest-common-divisor-of-strings.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/greatest-common-divisor-of-strings/) | ✅ 109 | 7 | [Find the position of M-th item](./goldman-sachs/find-the-position-of-m-th-item1723.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/find-the-position-of-m-th-item1723/1#) | ✅ 110 | 8 | [Total Decoding Messages](./goldman-sachs/total-decoding-messages1235.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/total-decoding-messages1235/1/) | ✅ 111 | 9 | [Number following a pattern](./goldman-sachs/number-following-a-pattern3126.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/number-following-a-pattern3126/1#) | ✅ 112 | 10 | [Max 10 numbers in a list having 10M entries](./goldman-sachs/k-largest-elements3736.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/k-largest-elements3736/1) | ✅ 113 | 11 | [Find Missing And Repeating](./goldman-sachs/find-missing-and-repeating2512.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/find-missing-and-repeating2512/1/#) | ✅ 114 | 12 | [Squares in N*N Chessboard](./goldman-sachs/squares-in-nn-chessboard1801.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/squares-in-nn-chessboard1801/1) | ✅ 115 | 13 | [Decode the string](./goldman-sachs/decode-the-string2444.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/decode-the-string2444/1) | ✅ 116 | 14 | [Minimum Size Subarray Sum](./goldman-sachs/minimum-size-subarray-sum.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/minimum-size-subarray-sum/) | ✅ 117 | 15 | [Array Pair Sum Divisibility Problem](./goldman-sachs/array-pair-sum-divisibility-problem3257.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/array-pair-sum-divisibility-problem3257/1#) | ✅ 118 | 119 |
120 | 121 |
122 | Amazon (15/15) 123 | 124 | Sr | [Problems](./amazon/README.md) | TryIt | Status 125 | ----|---------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|--------- 126 | 1 | [Maximum Profit](./amazon/maximum-profit.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/maximum-profit4657/1) | ✅ 127 | 2 | [Longest Mountain in Array](./amazon/longest-mountain-in-array.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/longest-mountain-in-array/) | ✅ 128 | 3 | [IPL 2021 - Match Day 2](./amazon/ipl-2021-match-day-2.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/deee0e8cf9910e7219f663c18d6d640ea0b87f87/1/) | ✅ 129 | 4 | [Brackets in Matrix Chain Multiplication](./brackets-in-matrix-chain-multiplication.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/brackets-in-matrix-chain-multiplication1024/1/) | ✅ 130 | 5 | [Phone directory](./amazon/phone-directory.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/phone-directory4628/1/) | ✅ 131 | 6 | [Maximum of all subarrays of size k](./amazon/maximum-of-all-subarrays-of-size.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/maximum-of-all-subarrays-of-size-k3101/1) | ✅ 132 | 7 | [First non-repeating character in a stream](./amazon/first-non-repeating-character-in-a-stream.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/first-non-repeating-character-in-a-stream1216/1) | ✅ 133 | 8 | [Count ways to N'th Stair(Order does not matter)](./amazon/count-ways-to-nth-stairorder-does-not-matter.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/count-ways-to-nth-stairorder-does-not-matter1322/1/) | ✅ 134 | 9 | [Is Sudoku Valid](./amazon/is-sudoku-valid.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/is-sudoku-valid4820/1/) | ✅ 135 | 10 | [Nuts and Bolts Problem](./amazon/nuts-and-bolts-problem.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/nuts-and-bolts-problem0431/1) | ✅ 136 | 11 | [Serialize and Deserialize a Binary Tree](./amazon/serialize-and-deserialize-a-binary-tree.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/serialize-and-deserialize-a-binary-tree/1) | ✅ 137 | 12 | [Column name from a given column number](./amazon/column-name-from-a-given-column-number.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/column-name-from-a-given-column-number4244/1/) | ✅ 138 | 13 | [Rotting Oranges](./amazon/rotting-oranges.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/rotting-oranges/) | ✅ 139 | 14 | [Burning Tree](./amazon/burning-tree.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/burning-tree/1/) | ✅ 140 | 15 | [Delete N nodes after M nodes of a linked list](./amazon/delete-n-nodes-after-m-nodes-of-a-linked-list.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/delete-n-nodes-after-m-nodes-of-a-linked-list/1/) | ✅ 141 | 142 |
143 | 144 |
145 | Microsoft (15/15) 146 | 147 | Sr | [Problems](./microsoft/README.md) | TryIt | Status 148 | ----|--------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------------|--------- 149 | 1 | [Minimum sum partition](./microsoft/minimum-sum-partition.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/minimum-sum-partition3317/1/) | ✅ 150 | 2 | [Prerequisite Tasks](./microsoft/prerequisite-tasks.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/prerequisite-tasks/1/) | ✅ 151 | 3 | [Rotate by 90 degree](./microsoft/rotate-by-90-degree.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/rotate-by-90-degree0356/1/) | ✅ 152 | 4 | [Spirally traversing a matrix](./microsoft/spirally-traversing-a-matrix.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/spirally-traversing-a-matrix-1587115621/1/) | ✅ 153 | 5 | [Stock span problem](./microsoft/stock-span-problem.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/stock-span-problem-1587115621/1) | ✅ 154 | 6 | [Possible Words From Phone Digits](./microsoft/possible-words-from-phone-digits.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/possible-words-from-phone-digits-1587115620/1/) | ✅ 155 | 7 | [Unit Area of largest region of 1's](./microsoft/length-of-largest-region-of-1s.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/length-of-largest-region-of-1s-1587115620/1/) | ✅ 156 | 8 | [Connect Nodes at Same Level](./microsoft/connect-nodes-at-same-level.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/connect-nodes-at-same-level/1/) | ✅ 157 | 9 | [Count Number of SubTrees having given Sum](./microsoft/count-number-of-subtrees-having-given-sum.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/count-number-of-subtrees-having-given-sum/1/) | ✅ 158 | 10 | [Stickler Thief](./microsoft/stickler-theif.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/stickler-theif-1587115621/1/) | ✅ 159 | 11 | [Generate Binary Numbers](./microsoft/generate-binary-numbers.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/generate-binary-numbers-1587115620/1/) | ✅ 160 | 12 | [Find All Four Sum Numbers](./microsoft/find-all-four-sum-numbers.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/find-all-four-sum-numbers1732/1) | ✅ 161 | 13 | [Bridge edge in a graph](./microsoft/bridge-edge-in-graph.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/bridge-edge-in-graph/1) | ✅ 162 | 14 | [Minimum steps to destination](./microsoft/minimum-steps-to-destination.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/minimum-number-of-steps-to-reach-a-given-number5234/1/) | ✅ 163 | 15 | [Alien Dictionary](./microsoft/alien-dictionary.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/alien-dictionary/1/) | ✅ 164 | 165 |
166 | 167 |
168 | Adobe (15/15) 169 | 170 | Sr | [Problems](./adobe/README.md) | TryIt | Status 171 | ----|-----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------- 172 | 1 | [Subarray with given sum](./adobe/subarray-with-given-sum.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/subarray-with-given-sum-1587115621/1) | ✅ 173 | 2 | [Longest Arithmetic Progression](./adobe/longest-arithmetic-progression.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/longest-arithmetic-progression1019/1/) | ✅ 174 | 3 | [No. of distict Words with k max contiguous vowels](./adobe/kmax-cont-vowels.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/7b9d245852bd8caf8a27d6d3961429f0a2b245f1/1/) | ✅ 175 | 4 | [Partition Equal Subset Sum](./adobe/subset-sum-problem.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/subset-sum-problem2014/1) | ✅ 176 | 5 | [Express as sum of power of natural numbers](./adobe/sum-of-power-of-natural-numbers.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/express-as-sum-of-power-of-natural-numbers5647/1) | ✅ 177 | 6 | [Generate Parentheses](./adobe/generate-parentheses.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/generate-all-possible-parentheses/1/) | ✅ 178 | 7 | Pots of Gold Game | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/pots-of-gold-game/1/) | ✅ 179 | 8 | [Implement Atoi](./adobe/implement-atoi.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/implement-atoi/1/) | ✅ 180 | 9 | [Next higher palindromic number using same digits](./adobe/next-higher-palindromic-number-same-digit.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/next-higher-palindromic-number-using-the-same-set-of-digits5859/1/) | ✅ 181 | 10 | [Winner of an election](./adobe/winner-of-an-election.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/winner-of-an-election-where-votes-are-represented-as-candidate-names-1587115621/1/) | ✅ 182 | 11 | [Amend The Sentence](./adobe/amend-the-sentence.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/amend-the-sentence3235/1) | ✅ 183 | 12 | [Leaders in an array](./adobe/leaders-in-an-array.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/leaders-in-an-array-1587115620/1/) | ✅ 184 | 13 | [Minimum operations to convert array A to B](./adobe/minimum-insertions-to-make-two-arrays-equal.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/minimum-insertions-to-make-two-arrays-equal/1/) | ✅ 185 | 14 | Smallest range in K lists | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/find-smallest-range-containing-elements-from-k-lists/1/) | ✅ 186 | 15 | [Most Recent Library](./adobe/most-recent-library.md) | | ✅ 187 | 188 |
189 | 190 |
191 | Intuit (15/15) 192 | 193 | Sr | Problems | TryIt | Status 194 | ----|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|-------- 195 | 1 | [Minimum sum partition](./intuit/minimum-sum-partition.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/minimum-sum-partition3317/1/) | ✅ 196 | 2 | [Word Search](./intuit/word-search.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/word-search/1/) | ✅ 197 | 3 | [Find the missing no in string](./intuit/missing-no-in-string.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/find-the-missing-no-in-string/1/) | ✅ 198 | 4 | [Largest number in K swaps](./intuit/largest-number-in-k-swaps.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/largest-number-in-k-swaps-1587115620/1) | ✅ 199 | 5 | [Split Array Largest Sum](./intuit/split-array-largest-sum.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/split-array-largest-sum/) | ✅ 200 | 6 | [Find in Mountain Array](./intuit/find-in-mountain-array.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/find-in-mountain-array/) | ✅ 201 | 7 | [Capacity To Ship Packages Within D Days](./intuit/capacity-to-ship-packages-within-d-days.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/) | ✅ 202 | 8 | [Number of Boomerangs](./intuit/number-of-boomerangs.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/number-of-boomerangs/) | ✅ 203 | 9 | [Pacific Atlantic Water Flow](./intuit/pacific-atlantic-water-flow.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/pacific-atlantic-water-flow/) | ✅ 204 | 10 | [Number of Provinces](./intuit/number-of-provinces.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/number-of-provinces/) | ✅ 205 | 11 | Construct Quad Tree | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/construct-quad-tree/) | ✅ 206 | 12 | Course Schedule II | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/course-schedule-ii/) | ✅ 207 | 13 | Minimum Swaps to Arrange a Binary Grid | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid/) | ✅ 208 | 14 | As Far from Land as Possible | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/as-far-from-land-as-possible/) | ✅ 209 | 15 | Koko Eating Bananas | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/koko-eating-bananas/) | ✅ 210 | 211 |
212 | 213 | 214 | 215 | 216 |
217 | Walmart (15/15) 218 | 219 | Sr | Problems | TryIt | Status 220 | ----|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|-------- 221 | 1 | Path with Maximum Probability | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/path-with-maximum-probability/) | ✅ 222 | 2 | Stone Game | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/stone-game/) | ✅ 223 | 3 | Remove Colored Pieces if Both Neighbors are the Same Color | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/) | ✅ 224 | 4 | [Number of Unique Paths](./walmart/number-of-unique-paths.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/number-of-unique-paths5339/1/) | ✅ 225 | 5 | [Transform to Sum Tree](./walmart/transform-to-sum-tree.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/transform-to-sum-tree/1/) | ✅ 226 | 6 | [Power Of Numbers](./walmart/power-of-numbers.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/power-of-numbers-1587115620/1/) | ✅ 227 | 7 | [Sorted subsequence of size 3](./walmart/sorted-subsequence-of-size-3.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/sorted-subsequence-of-size-3/1/) | ✅ 228 | 8 | [Maximum Height Tree](./walmart/maximum-height-tree.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/maximum-height-tree4803/1/) | ✅ 229 | 9 | Guess Number Higher or Lower II | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/guess-number-higher-or-lower-ii/) | ✅ 230 | 10 | Generate Random Point in a Circle | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/generate-random-point-in-a-circle/) | ✅ 231 | 11 | Maximum Performance of a Team | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/maximum-performance-of-a-team/) | ✅ 232 | 12 | Find Array Given Subset Sums | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/find-array-given-subset-sums/) | ✅ 233 | 13 | [Find the Kth Largest Integer in the Array](./walmart/find-the-kth-largest-integer-in-the-array.md) | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/find-the-kth-largest-integer-in-the-array/) | ✅ 234 | 14 | [Largest number in K swaps](./walmart/largest-number-in-k-swaps.md) | [![Problem Link](./assets/gfg.svg)](https://practice.geeksforgeeks.org/problems/largest-number-in-k-swaps-1587115620/1/) | ✅ 235 | 15 | Divide Two Integers | [![Problem Link](./assets/lc.svg)](https://leetcode.com/problems/divide-two-integers/) | ✅ 236 | 237 |
238 | 239 | 240 | --------------------------------------------------------------------------------