- Program that calculate the fractions of its elements that are positive, negative and zeros.
Sample Input:
8
-3 -2 -1 0 0 1 2 3
Sample Output:
0.375
0.25
0.375
Explanation:
Number of positive elements / total elements = 3/8 = 0.375
Number of zero elements / total elements = 2/8 = 0.25
Number of negative elements / total elements = 3/8 = 0.375
- Program to insert an element at given position in array.
Sample Input:
5
10 20 30 40 50
2
25
Sample Output:
10 20 25 30 40 50
Explanation:
n = 5
arr[] = {10,20,30,40,50}
pos = 2
newelement = 25
New Array after insertion is {10,20,25,30,40,50}
- Program to delete an element from an array at specified position.
Sample Input:
5
10 20 30 40 50
2
Sample Output:
10 20 40 50
Explanation:
n = 5
arr[] = {10,20,30,40,50}
Position to be delete 2
New Array after element delete {10,20,40,50}
- Program to reverse of array elements.
Sample Input:
5
10 20 30 40 50
Sample Output:
50 40 30 20 10
- Program to remove duplicates in array.
Sample Input:
6
1 2 3 2 4 2
Sample Output:
1 2 3 4
- Program to count the frequency of each element of an array.
Sample Input:
6
1 2 3 2 4 2
Sample Output:
1 1
2 3
3 1
4 1
- Program to sort the elements in array.
Sample Input:
5
3 4 2 5 1
Sample Output:
1 2 3 4 5
Explanation:
Arrange the array elements in ascending order.
- Program to find second smallest and second largest numbers from array.
Sample Input:
8
4 6 1 5 2 7 3 8
Sample Output:
2 7
- Program for left rotate of array.
Sample Input:
6
1 2 3 4 5 6
2
Sample Output:
3 4 5 6 1 2
Explanation:
n = 6
arr[] = {1,2,3,4,5,6}
After first left rotation, arr[] becomes {2,3,4,5,6,1} and after the second rotation, arr[] becomes {3,4,5,6,1,2}
- Program to find duplicate element in k-distance. If found print "YES" otherwise "NO".
Sample Input1:
8
1 2 3 4 1 2 3 4
3
Sample Output1:
NO
Explanation:
Each element in the given array arr[] appears twice and the distance between every element and its duplicate is 4.
Sample Input1:
6
1 2 3 2 4 5
3
Sample Output1:
YES
Explanation:
2 is present at index 1 and 3.