Skip to content

Commit 302cef1

Browse files
committed
Day - 91 work
1 parent 2d99be0 commit 302cef1

10 files changed

+103
-8
lines changed

README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
| Current Status| Stats |
88
| :------------: | :----------: |
9-
| Total Problems | 129 |
10-
| Current Streak | 90 days |
11-
| Longest Streak | 90 ( August 17, 2015 - November 14, 2015 ) |
9+
| Total Problems | 130 |
10+
| Current Streak | 91 days |
11+
| Longest Streak | 91 ( August 17, 2015 - November 15, 2015 ) |
1212

1313
</center>
1414

@@ -129,11 +129,12 @@ Include contains single header implementation of data structures and some algori
129129
### Common Data Structure and logic problems
130130
| Problem | Solution |
131131
| :------------ | :----------: |
132-
| Print the contents of matrix in a spiral order | [matrix_spiral_print.cpp](common_ds_problems/matrix_spiral_print.cpp)
133-
| Given a M x N matrix, rotate it by R rotations anticlockwise, and show the resulting matrix. | [rotate_matrix.cpp](common_ds_problems/rotate_matrix.cpp)|
134-
| Rotate an array by r elements ( left or right ) | [array_rotation.cpp](common_ds_problems/array_rotation.cpp)
135-
| Given an array of repeating/non-repeating intergeres, determine the first non-repeating int in this array | [first_non_repeating_int.cpp](common_ds_problems/first_non_repeating_int.cpp)|
136-
| 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_problems/save_quantumland.cpp)|
132+
| Print the contents of matrix in a spiral order | [matrix_spiral_print.cpp](common_ds_algo_problems/matrix_spiral_print.cpp)
133+
| Given a M x N matrix, rotate it by R rotations anticlockwise, and show the resulting matrix. | [rotate_matrix.cpp](common_ds_algo_problems/rotate_matrix.cpp)|
134+
| Rotate an array by r elements ( left or right ) | [array_rotation.cpp](common_ds_algo_problems/array_rotation.cpp)
135+
| 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+
| 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]|
137138

138139
### Math Problems
139140
| Problem | Solution |
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* 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.
3+
* For N=24, there are 2 digits (2 & 4). Both of these digits exactly divide 24. So our answer is 2.
4+
*
5+
* Note
6+
*
7+
* If the same number is repeated twice at different positions, it should be counted twice,
8+
* e.g., For N=122, 2 divides 122 exactly and occurs at ones' and tens' position. So for this case, our answer is 3.
9+
* Division by 0 is undefined.
10+
*
11+
*
12+
* Input Format
13+
* The first line contains T (the number of test cases), followed by T lines (each containing an integer N).
14+
*
15+
* Constraints
16+
* 1≤T≤15
17+
* 0<N<1010
18+
* Output Format
19+
*
20+
* For each test case, display the count of digits in N that exactly divide N in a separate line.
21+
*
22+
* Sample Input
23+
*
24+
* 2
25+
* 12
26+
* 1012
27+
*
28+
* Sample Output
29+
* 2
30+
* 3
31+
*/
32+
33+
#include <cmath>
34+
#include <cstdio>
35+
#include <vector>
36+
#include <iostream>
37+
#include <algorithm>
38+
using namespace std;
39+
40+
41+
int main() {
42+
int T, num;
43+
cin >> T;
44+
for (int t = 0; t < T; ++t) {
45+
cin >> num;
46+
int c = 0, d =0;
47+
int x = num;
48+
while(x > 0) {
49+
d = x % 10;
50+
if ( d != 0 && num % d == 0) {
51+
++c;
52+
}
53+
x = x/10;
54+
}
55+
cout << c << endl;
56+
}
57+
return 0;
58+
}
59+

common_ds_algo_problems/minHeap.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
template <typename T>
5+
class Heap {
6+
T * arr;
7+
size_t capacity;
8+
size_t heap_size;
9+
10+
public:
11+
Heap( T * arr, size_t heap_size );
12+
T left( size_t i ) { return ( i - 1 )/2; }
13+
T right( size_t i ) { return (2 * i + 1); }
14+
T parent( size_t i ) { return ( 2 * i + 2 ); }
15+
void minHeapify( size_t i );
16+
T getMin() { return arr[0]; }
17+
int extractMin();
18+
};
19+
20+
Heap::Heap(T * harr, size_t heapSize ) {
21+
heap_size = heapSize;
22+
arr = harr;
23+
size_t i = ( heap_size - 1 )/ 2;
24+
while ( i >= 0 ) {
25+
minHeapify(i);
26+
i--;
27+
}
28+
}
29+
30+
template <typename T>
31+
T Heap::extractMin() {
32+
if (heap_size == 0 ) {
33+
34+
}
35+
}

common_ds_algo_problems/run

9.44 KB
Binary file not shown.

tree_problems/run

57.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)