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
Given 2 sorted arrays (Sorted in ascending order). You have to print out the numbers which are in intersection of these 2 arrays. Print -1 if there is intersection is empty.
4
+
5
+
Input
6
+
First line is n which denotes the number of elements in first array. Following n lines are elements for the first array.
7
+
Next line is m which denotes the number of elements in second array. Following m lines are elements for the second array.
8
+
9
+
Output
10
+
k lines representing the numbers which are common to both the arrays.
11
+
12
+
Example
13
+
Input:
14
+
15
+
4
16
+
1
17
+
1
18
+
2
19
+
2
20
+
3
21
+
2
22
+
2
23
+
5
24
+
Output:
25
+
26
+
2
27
+
2
28
+
Explanation
29
+
First line is 4, i.e. 4 elements in the first array. So the first array is [1,1,2,2].
30
+
m is 3, so the second array is [2,2,5].
31
+
Comparing the 2 arrays, common elements to both of them are [2,2] which is our output.
Given a sorted array of n integers, a lucky integer is an integer which has a frequency in the array equal to its value.
4
+
5
+
Return a lucky integer in the array. If there is no lucky integer return -1.
6
+
7
+
If you have multiple lucky integers, please return the first lucky integer in the array (lucky number with the least index).
8
+
9
+
Input
10
+
First line contains a positive integer n, denoting the number of elements in the array. It is followed by n lines. Each line contains one integer denoting an element in the array.
11
+
12
+
Output
13
+
One line specifying the lucky integer in the array
14
+
15
+
Example
16
+
Input:
17
+
18
+
4
19
+
2
20
+
2
21
+
3
22
+
4
23
+
Output:
24
+
25
+
2
26
+
Explanation
27
+
First line is 4, i.e. 4 elements in the array. The array is [2,2,3,4]. We can see that number 2 is repeating 2 times hence it is the lucky number which is our output
Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i].
4
+
5
+
Return the answer in an array.
6
+
7
+
Input
8
+
First line consists of a single integer, denoting N, length of array.
9
+
10
+
Next N lines containing one integer per line denoting the elements of array A.
11
+
12
+
Output
13
+
Print the resultant array, one element in one line.
14
+
15
+
Constraints:
16
+
2 <= nums.length <= 500
17
+
0 <= nums[i] <= 100
18
+
Example
19
+
Input:
20
+
21
+
5
22
+
23
+
8
24
+
25
+
1
26
+
27
+
2
28
+
29
+
2
30
+
31
+
3
32
+
33
+
Output:
34
+
35
+
4
36
+
37
+
0
38
+
39
+
1
40
+
41
+
1
42
+
43
+
3
44
+
45
+
Explanation
46
+
nums = [8,1,2,2,3]
47
+
48
+
Output: [4,0,1,1,3]
49
+
50
+
For nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3).
51
+
52
+
For nums[1]=1 does not exist any smaller number than it.
53
+
54
+
For nums[2]=2 there exist one smaller number than it (1).
55
+
56
+
For nums[3]=2 there exist one smaller number than it (1).
57
+
58
+
For nums[4]=3 there exist three smaller numbers than it (1, 2 and 2).
0 commit comments