-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathomnious number.cpp
65 lines (48 loc) · 1.54 KB
/
omnious number.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
/*
https://www.geeksforgeeks.org/samsung-interview-experience-set-40-campus-white-box-testing/
https://www.geeksforgeeks.org/samsung-rd-sri-noida-on-campus-interview-experience/
https://code.hackerearth.com/01ac52j?key=b462f0a802c8c1faf1d87f2b1353b9ce
Company A is discarding product numbers that contain few specific digits a specific number of time or
more than that. You are given a range and you need to find product numbers that are possible.
Example-
Range: 24 to 12943
Numbers that should not come: 1, 3, 5
Number of times these number should not occur: 3 or more
In above case all two digit numbers are valid.
In three digit: 111, 113, 115, 311, 331, 333, 511, 533, 555 are not valid.
In four digit: All the numbers containing above 3 digit numbers are not valid.
Eg: 11223 is not valid, 11222 is valid.
*/
#include <iostream>
using namespace std;
int numberOminous(int a, int b, int k, int *delNos, int n){
int count = 0;
for(int i = a; i <= b; i++){
int temp = i;
int digitArray[10] = {0};
while(temp){
digitArray[temp%10]++;
temp /= 10;
}
int rougeK = 0;
for(int i=0; i<n; i++){
rougeK += digitArray[delNos[i]];
}
if(rougeK < k){
count++;
}
}
return count;
}
int main() {
int a, b, k;
cin >> a >> b >> k;
int n;
cin >> n;
int *delNos = new int[n];
for(int i=0; i<n; i++){
cin >> delNos[i];
}
cout << numberOminous(a, b, k, delNos, n) << "\n";
return 0;
}