You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-14Lines changed: 21 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@
20
20
| Swap nodes of a linkedlist without swapping data. |[swapNodesWithoutSwappingData.cpp](linked_list_problems/swapNodesWithoutSwappingData.cpp)|
21
21
| Reverse a linked list, iteratively and recursively |[reverseLinkedListIterAndRecurse.cpp](linked_list_problems/reverseLinkedListIterAndRecurse.cpp)|
22
22
| Given a linked list, reverse alternate nodes and append at the end. |[reverseAlternateNodes.cpp](linked_list_problems/reverseAlternateNodes.cpp)|
23
-
| Only given a node pointer, delete the node from the linked list. |[deleteNode.cpp](linked_list_problems/deleteNode.cpp)|
23
+
| Only given a node pointer, delete the node from the linked list. |[deleteNode.cpp](linked_list_problems/deleteNode.cpp)|
24
24
| Delete the entire linkedlist. |[deleteLinkedlist.cpp](linked_list_problems/deleteLinkedlist.cpp)|
25
25
| Print middle node of linkedlist without iterating twice. |[printMiddleNode.cpp](linked_list_problems/printMiddleNode.cpp)|| Detecting and removing a cycle in linkedlist.|[floyedCycleDetection.cpp](linked_list_problems/floyedCycleDetection.cpp)|
26
26
| Determine if a linked list is a pallindrome. |[listPallindrome.cpp](linked_list_problems/listPallindrome.cpp)|
@@ -40,18 +40,19 @@ Include contains single header implementation of data structures and some algori
40
40
| Generic Macros and Algorithms like swap, random number generation |[generic.h](include/generic.h)|
| My own string library implementation |[pstring.h](include/pstring.h)[pstring.cpp](include/pstring.cpp)|
53
53
54
-
###Bit Manipulation Problems
54
+
### Bit Manipulation Problems
55
+
55
56
| Problem | Solution |
56
57
| :------------ | :----------: |
57
58
| Determine if a number is a power of 2. |[power_of_2.cpp](bit_manipulation/power_of_2.cpp)|
@@ -67,8 +68,14 @@ Include contains single header implementation of data structures and some algori
67
68
| Given two integers, determine if their sum would be interger overflow.|[integerOverflow.cpp](bit_manipulation/integerOverflow.cpp)|
68
69
| How many bit flip operation would require to convert number A to B. |[countNumberOfBitFlips.cpp](bit_manipulation/countNumberOfBitFlips.cpp)|
69
70
| Given a number x and two positions (from right side) in binary representation of x, write a function that swaps n right bits at given two positions and returns the result. It is also given that the two sets of bits do not overlap.|[swapSetOfBits.cpp](bit_manipulation/swapSetOfBits.cpp)|
70
-
| Add two numbers without using any arithmetic operators | [addition_without_operators.cpp](bit_manipulation/addition_without_operators.cpp)
71
-
| Louise and Richard play a game. They have a counter set to N. Louise gets the first turn and the turns alternate thereafter. In the game, they perform the following operations: <ul><li>If N is not a power of 2, reduce the counter by the largest power of 2 less than N.</li></ul><ul><li>If N is a power of 2, reduce the counter by half of N.</li></ul> The resultant value is the new N which is again used for subsequent operations.The game ends when the counter reduces to 1, i.e., N == 1, and the last person to make a valid move wins. <ul><li> Given N, your task is to find the winner of the game. If they set counter to 1, Richard wins, because its Louise' turn and she cannot make a move.</li></ul><ul><li>Input Format : -The first line contains an integer T, the number of testcases. T lines follow. Each line contains N, the initial number set in the counter.|[counter_game.cpp](bit_manipulation/counter_game.cpp)|
71
+
| Add two numbers without using any arithmetic operators |[addition_without_operators.cpp](bit_manipulation/addition_without_operators.cpp)|
72
+
73
+
Louise and Richard play a game. They have a counter set to N. Louise gets the first turn and the turns alternate thereafter. In the game, they perform the following operations: <ul><li>If N is not a power of 2, reduce the counter by the largest power of 2 less than N.</li></ul><ul><li>If N is a power of 2, reduce the counter by half of N.</li></ul> The resultant value is the new N which is again used for subsequent operations.The game ends when the counter reduces to 1, i.e., N == 1, and the last person to make a valid move wins. <ul><li> Given N, your task is to find the winner of the game. If they set counter to 1, Richard wins, because its Louise' turn and she cannot make a move.</li></ul><ul><li>Input Format : -The first line contains an integer T, the number of testcases. T lines follow. Each line contains N, the initial number set in the counter.
@@ -93,7 +100,7 @@ Include contains single header implementation of data structures and some algori
93
100
| Problem 2-7: Determine if two singly linked list intersect, if yes, return the intersecting node. The intersection is defined based on reference not on values|[2-7-intersection.cpp](cracking_the_coding_interview_problems/2-7-intersection.cpp)|
94
101
| Problem 2-8: Detect if the linked list have a loop, Find the start node of the loop and remove the loop| [2-8-loop-detection.cpp](cracking_the_coding_interview_problems/2-8-loop-detection.cpp)
95
102
96
-
###Dynamic Programming Problems
103
+
###Dynamic Programming Problems
97
104
| Problem | Solution |
98
105
| :------------ | :----------: |
99
106
| N<sup>th</sup> Fibonacci term using different memoization techniques |[fibonacci.cpp](dynamic_programming_problems/fibonacci.cpp)|
@@ -134,12 +141,12 @@ Include contains single header implementation of data structures and some algori
134
141
| Rotate an array by r elements ( left or right ) | [array_rotation.cpp](common_ds_algo_problems/array_rotation.cpp)
135
142
| Given an array of repeating/non-repeating intergeres, determine the first non-repeating int in this array |[first_non_repeating_int.cpp](common_ds_algo_problems/first_non_repeating_int.cpp)|
136
143
| In Quantumland, there are n cities numbered from 1 to n. Here, c<sub>i</sub> denotes the i<sup>th</sup> city. There are n−1 roads in Quantumland. Here, c<sub>i</sub> and c<sub>i+1</sub> have a bidirectional road between them for each i < n.There is a rumor that Flatland is going to attack Quantumland, and the queen wants to keep her land safe. The road between c<sub>i</sub> and c<sub>i+1</sub> is safe if there is a guard in c<sub>i</sub> or c<sub>i+1</sub>. The queen has already placed a few guards in some of the cities, but she is not sure if they are enough to keep the roads safe. She wants to know the minimum number of new guards she needs to hire. See comments in solution for input/output details. |[save_quantamland.cpp](common_ds_algo_problems/save_quantumland.cpp)|
137
-
| You are given an integer N. Find the digits in this number that exactly divide N (division that leaves 0 as remainder) and display their count. For N=24, there are 2 digits (2 & 4). Both of these digits exactly divide 24. So our answer is 2. See more details in header comment of the solution file. |[findDigits.cpp](common_ds_algo_problems/findDigits.cpp]|
144
+
| You are given an integer N. Find the digits in this number that exactly divide N (division that leaves 0 as remainder) and display their count. For N=24, there are 2 digits (2 & 4). Both of these digits exactly divide 24. So our answer is 2. See more details in header comment of the solution file. |[findDigits.cpp](common_ds_algo_problems/findDigits.cpp)|
138
145
139
146
### Math Problems
140
147
| Problem | Solution |
141
148
| :------------ | :----------: |
142
-
| Print all the permutations of a string. Example: Permutations of ABC are ABC, ACB, BCA, BAC, CAB, CBA |[string_permutations.cpp](math_problems/string_permutations.cpp) |
149
+
| Print all the permutations of a string. Example: Permutations of ABC are ABC, ACB, BCA, BAC, CAB, CBA |[string_permutations.cpp](math_problems/string_permutations.cpp)|
143
150
| Euclidean algorithm to find greatest common divisor of two numbers. (Iterative and recursive)|[gcd.cpp](math_problems/gcd.cpp)|
144
151
| Implement pow(x,y) using divide and conquer approach. Try implementing it in O(logn)|[pow.cpp](math_problems/pow.cpp)|
145
152
| Calculate factorial of large number, say 100 (it will have 158 digits) |[factorial_of_large_num.cpp](math_problems/factorial_of_large_num.cpp)|
@@ -174,7 +181,7 @@ Include contains single header implementation of data structures and some algori
174
181
| Calculate total weight of Minimum Spanning Tree of a given graph ( sum of weights of edges which forms MST) using Prim's algorithm |[primsMST.cpp](graph_problems/primsMST.cpp)|
175
182
| Print Minimum Spanning Tree( MST ) of a given graph using Kruskal's algorithm.|[kruskalMST.cpp](graph_problems/kruskalMST.cpp)|
176
183
177
-
###Greedy Problems
184
+
###Greedy Problems
178
185
| Problem | Solution |
179
186
| :------------ | :----------: |
180
187
| Given two integer arrays, A and B, each containing N integers. You are free to permute the order of the elements in the arrays. Is there an permutation A', B' possible of A and B, such that, A'<sub>i</sub>+B'<sub>i</sub> ≥ K for all i, where A'<sub>i</sub> denotes the i<sup>th</sup> element in the array A' and B'<sub>i</sub> denotes i<sup>th</sup> element in the array B'.|[two_arrays.cpp](greedy_problems/two_arrays.cpp)|
0 commit comments