Day 01
Day 01
Given an array arr[] and an integer k where k is smaller than the size of the array, your task is to
find the kth smallest element in the given array.
Examples :
Constraints:
1 <= arr.size <= 106
1<= arr[i] <= 106
1 <= k <= n
Question 02:-
Given an array arr, rotate the array by one position in clockwise direction.
Examples:
Constraints:
1<=arr.size()<=105
0<=arr[i]<=105
Question 03:-
Given an array arr[], the task is to reverse the array. Reversing an array means rearranging the
elements such that the first element becomes the last, the second element becomes second
last and so on.
Examples:
Question 04:-
Given an array arr[] denoting heights of N towers and a positive integer K.
For each tower, you must perform exactly one of the following operations exactly once.
Find out the minimum possible difference between the height of the shortest and tallest towers
after you have modified each tower.
Examples :
Output: 5
Explanation: The array can be modified as {1+k, 5-k, 8-k, 10-k} = {3, 3, 6, 8}.The difference
between the largest and the smallest is 8-3 = 5.
Output: 11
Explanation: The array can be modified as {3+k, 9+k, 12-k, 16-k, 20-k} -> {6, 12, 9, 13, 17}.The
difference between the largest and the smallest is 17-6 = 11.
Constraints
1 ≤ k ≤ 107
1 ≤ n ≤ 105
1 ≤ arr[i] ≤ 107
Question 05:-
Given an array of integers nums containing n + 1 integers where each integer is in the range [1,
n] inclusive.
There is only one repeated number in nums, return this repeated number.
You must solve the problem without modifying the array nums and using only constant extra
space.
Example 1:
Output: 2
Example 2:
Output: 3
Example 3:
Output: 3
Constraints:
● nums.length == n + 1