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

Efficient sorting algorithms

Ok

Uploaded by

shiva2000web
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Efficient sorting algorithms

Ok

Uploaded by

shiva2000web
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Find the smallest subarray length such that if we sort it,

whole array will be sorted

arr = {1, 2, 5, 3, 6, 10, 9, 21, 25}


Find the smallest subarray length such that if we sort it,
whole array will be sorted

arr = {1, 2, 5, 3, 0, 12, 13, 8, 15, 18}


You have a binary string S of length N. In one operation you
can select a substring of S and reverse it. Find
the minimum number of operations required to sort
this binary string.

3
000 = 0
4
1001= 1
4
1010 = 2
6
010101 = 2
Given string str consisting of uppercase and lowercase characters.
The task is to sort uppercase and lowercase characters separately
such that if the ith place in the original string had an uppercase
character, then it should not have a lowercase character after being
sorted and vice versa.

Input : str = “eDefSR”


Output: eDefRS

Input : str = “srbDKi”


Output: birDKs
Count the number of pairs with difference k
Given an array arr and integer k, return the number of pairs(i,j)
where i<j

Case 1. Input = [1,2,2,1], k=1


Output = 4
[1,2,2,1]
[1,2,2,1]
[1,2,2,1]
[1,2,2,1]

Case 2: Input = [1,3], k=3


Output = 0
Problem Statement: Given an array of integers and an
integer k, return the total number of subarrays whose sum
equals k.
A subarray is a contiguous non-empty sequence of elements
within an array.
arr[]= [1,2,3,-3,1,1,1,4,2,-3]

You might also like