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

Ques File

Uploaded by

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

Ques File

Uploaded by

HACKERS HOVEL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 2
Divi le & Conquer QUESTIONS Question 1 : Apply Merge sort to sort an array of Strings. (Assume that all the characters in all the Strings are in lowercase). (EASY) ‘Sample Input 1: arr = {"sur’, ‘earth’, ‘mars’, ‘mercury’ } ‘Sample Output 1: arr = {“earth’, ‘mars’, ‘mercury’, "sun’} Question 2 : Given an array nums of size n, return the majority element. (MEDIUM) The majority element is the element that appears more than Ln / 2J times. You may assume that the majority element always exists in the array. Sample Input 1 : nums = [3.2.3] Sample Output 1:3 Sample Input 2: nums =[2.2,1,1,1.2.2] ‘Sample Output 2 °2 Constraints (extra Conditions): == numsiength © 1 al] and i< ‘Sample Input 1: N = 5, arr{] = (2, 4, 1,3, 5) ‘Sample Output 1: 3, because it has 3 inversions - (2, 1), (4, 1), (4,3) ‘Sample Input 2: N = 5, arr[] = (2,3, 4,5, 6) Sample Output 2 °0, because the array is already sorted ‘Sample Input 3 : N = 3, arr(] = {5, 5, 5) Sample Output 3 0, because all the elements of the array are the same & already in a sorted manner. (Hint: A sorting algorithm will be used to solve this question.) Note - This question is important. Even if you are not able to come up with the approach, please understand the solution. COLLEGE

You might also like