0% found this document useful (0 votes)
111 views4 pages

InfyTQ Practice Problem - Day 21

The document discusses three problems: 1. Given a string, find the length of the longest substring with all distinct characters. 2. Given a string with words separated by dots, reverse the order of the words without reversing the individual words. 3. Given two arrays, check if the elements of the second array are a subset of the first array.

Uploaded by

Roshan Prasad
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)
111 views4 pages

InfyTQ Practice Problem - Day 21

The document discusses three problems: 1. Given a string, find the length of the longest substring with all distinct characters. 2. Given a string with words separated by dots, reverse the order of the words without reversing the individual words. 3. Given two arrays, check if the elements of the second array are a subset of the first array.

Uploaded by

Roshan Prasad
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

Day 21

Question 1: Longest Distinct characters in string

Given a string S, find length of the longest substring with all distinct characters.

Example 1:

Input:

S = "geeksforgeeks"

Output: 7

Explanation: "eksforg" is the longest

substring with all distinct characters.

​Example 2:

Input:

S = "aaa"

Output: 1

Explanation: "a" is the longest substring

with all distinct characters.

Your Task:

You don't need to read input or print anything. Your task is to complete the

function longestSubstrDitinctChars() which takes the string S as input and returns the length of the longest

substring with all distinct characters.

Expected Time Complexity: O(|S|).

Expected Auxiliary Space: O(K), where K is Constant.

Constraints:

1<=|S|<=105
Question 2: Reverse words in a given string

Given a String S, reverse the string without reversing its individual words. Words are separated by dots.

Example 1:

Input:

S = i.like.this.program.very.much

Output: much.very.program.this.like.i

Explanation: After reversing the whole


string(not individual words), the input

string becomes

much.very.program.this.like.i

Example 2:

Input:

S = pqr.mno

Output: mno.pqr

Explanation: After reversing the whole

string , the input string becomes

mno.pqr

Your Task:

You dont need to read input or print anything. Complete the function reverseWords() which takes string S as

input parameter and returns a string containing the words in reversed order. Each word in the returning string

should also be separated by '.'

Expected Time Complexity: O(|S|)

Expected Auxiliary Space: O(|S|)

Constraints:

1 <= |S| <= 105


Question 3: Array Subset of another array

Given two arrays: a1[0..n-1] of size n and a2[0..m-1] of size m. Task is to check whether a2[] is a subset of a1[]

or not. Both the arrays can be sorted or unsorted.

Example 1:

Input:

a1[] = {11, 1, 13, 21, 3, 7}

a2[] = {11, 3, 7, 1}

Output:

Yes

Explanation:

a2[] is a subset of a1[]

Example 2:

Input:

a1[] = {1, 2, 3, 4, 5, 6}

a2[] = {1, 2, 4}

Output:

Yes

Explanation:

a2[] is a subset of a1[]

Example 3:

Input:

a1[] = {10, 5, 2, 23, 19}

a2[] = {19, 5, 3}

Output:

No

Explanation:

a2[] is not a subset of a1[]


Your Task:

You don't need to read input or print anything. Your task is to complete the function isSubset() which takes the

array a1[], a2[], its size n and m as inputs and return "Yes" if arr2 is subset of arr1 else return "No" if arr2 is not

subset of arr1.

Expected Time Complexity: O(n)

Expected Auxiliary Space: O(n)

Constraints:

1 <= n,m <= 105

1 <= a1[i], a2[j] <= 106

You might also like