Skip to content

Commit d3f161d

Browse files
committed
check_if_n_and_its_double_exist.cpp
1 parent 188e952 commit d3f161d

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
| S.No. | Topic | Status |
66
|---|--------------|-----|
7-
|01. | [Array](https://github.com/geeky01adarsh/DSA-Interview-Questions/tree/main/Arrays) | 24/28 |
8-
|02. | [Searching](/Searching)|14/38|
7+
|01. | [Array](/Arrays) | 24/28 |
8+
|02. | [Searching](/Searching)|15/38|
99
|03. | [Sorting](/Sorting)|0/38|

Searching/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
|11| [Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays/)|[Solution](intersection_of_two_arrays_i.cpp)|
1717
|12| [Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/)|[Solution](intersection_of_two_arrays_ii.cpp)|
1818
|13| [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap/)|Pending|
19-
|14| [Check If N and Its Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist/)|Pending|
19+
|14| [Check If N and Its Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist/)|[Solution](check_if_n_and_its_double_exist.cpp)|
2020
|15| [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x/)|Pending|
2121
|16| [Binary Search](https://leetcode.com/problems/binary-search/)|[Solution](binary_search.cpp)|
2222
|17| [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower/)|[Solution](guess_no_higher_lower.cpp)|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
bool checkIfExist(vector<int> &arr)
5+
{
6+
unordered_map<int, int> map;
7+
for (int i = 0; i < arr.size(); i++)
8+
{
9+
map[arr[i]]++;
10+
if (arr[i] == 0 && map[arr[i]] == 1)
11+
continue;
12+
if (map.count(2 * arr[i]) > 0 || ((arr[i] % 2 == 0) && map.count(arr[i] / 2) > 0))
13+
return true;
14+
}
15+
return false;
16+
}
17+
18+
int main()
19+
{
20+
int n;
21+
cin >> n;
22+
vector<int> v;
23+
for (int i = 0; i < n; i++)
24+
{
25+
int temp;
26+
cin >> temp;
27+
v.push_back(temp);
28+
}
29+
cout << checkIfExist(v) << endl;
30+
return 0;
31+
}

0 commit comments

Comments
 (0)