0% found this document useful (0 votes)
6 views

Week Assignment Questions

Uploaded by

23eg505r02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Week Assignment Questions

Uploaded by

23eg505r02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Qus 1:-

A left rotation operation on an array shifts each of the array's elements unit to
the left. For example, if left rotations are performed on array , then the array
would become . Note that the lowest index item moves to the highest index in
a rotation. This is called a circular array.
Given an array of integers and a number, , perform left rotations on the array.
Return the updated array to be printed as a single line of space-separated
integers.

Sample Input
54
12345
Sample Output
51234

Qus 2:-
You are given an unordered array consisting of consecutive integers [1, 2, 3, ...,
n] without any duplicates. You are allowed to swap any two elements. Find the
minimum number of swaps required to sort the array in ascending order.
Example
Arr=[7,1,3,2,4,5,6]
Perform the following steps:
i arr swap (indices)
0 [7, 1, 3, 2, 4, 5, 6] swap (0,3)
1 [2, 1, 3, 7, 4, 5, 6] swap (0,1)
2 [1, 2, 3, 7, 4, 5, 6] swap (3,4)
3 [1, 2, 3, 4, 7, 5, 6] swap (4,5)
4 [1, 2, 3, 4, 5, 7, 6] swap (5,6)
5 [1, 2, 3, 4, 5, 6, 7]
It took 5 swaps to sort the array.
Sample Input 0
4
4312
Sample Output 0
3
Qus 3:-
You are given an array and you need to find number of tripets of indices such
that the elements at those indices are in geometric progression for a given
common ratio r and i<j<k.

Example

arr=[1,4,16,64] r=4
There are [1,4,16] and [4,16,64] at indices (0,1,2) and (1,2,3) . Return 2.

Sample Input 0
42
1224
Sample Output 0
2

Qus 4:-
Given an array of integers, find all unique triplets in the array that sum up to
zero.
Input:
arr = [-1, 0, 1, 2, -1, -4]
Output:
[[-1, -1, 2], [-1, 0, 1]]

Qus 5:-
Merge Two Sorted Arrays
Problem Statement:
Given two sorted arrays, merge them into a single sorted array.
Input:
arr1 = [1, 3, 5]
arr2 = [2, 4, 6]
Output:
[1, 2, 3, 4, 5, 6]
Qus 7:-
Count the Frequency of Each Element
Problem Statement:
Given an array, count the frequency of each unique element.
Input:
arr = [1, 2, 2, 3, 1, 4, 2]
Output:
{1: 2, 2: 3, 3: 1, 4: 1}
Qus 7:-
Find the Longest Consecutive Sequence
Problem Statement:
Find the length of the longest consecutive elements sequence in an unsorted
array.
Input:
arr = [100, 4, 200, 1, 3, 2]
Output:
4
(Explanation: The longest sequence is [1, 2, 3, 4].)
Qus 8:-
Sort an Array of 0s, 1s, and 2s
Problem Statement:
Sort an array containing only 0s, 1s, and 2s without using any sorting algorithm.
Input:
arr = [0, 1, 2, 0, 1, 2, 1, 0]
Output:
[0, 0, 0, 1, 1, 1, 2, 2]

You might also like