Question: DeShaw Online Assessment (OA) Coding Questions | HackerRank | Same Substring | Diverse Deputation
0
Entering edit mode

Question 1: Same Substring

Problem Statement:

Two strings, s and t, each of length n, that contain lowercase English characters are given as well as an integer K.

  • The cost to change the ith character in s from si to ti is the absolute difference of the ASCII value of characters, i.e., abs(si - ti).

Find the maximum length of a substring of s that can be changed to the corresponding substring of t with a total cost less than or equal to K. If there is no such substring, return 0.

Example:

s = "adpgki", t = "cdmxki", K = 6.

  • Change s0 from 'a' to 'c' with cost = abs('a' - 'c') = 2. String s is now "cdpgki" and K = 6 - 2 = 4.
  • Change s2 from 'p' to 'm' with cost = abs('p' - 'm') = 3. String s is now "cdmgki" and K = 4 - 3 = 1.
  • The only character left to change is 'g' to 'x', which costs more than K.

The longest substring in s that is equal to the corresponding substring in t is s[0, 2] = t[0, 2]. Hence, the answer is 3.

Constraints:

  • Strings s and t contain lowercase English letters only.

 

Question 2: Diverse Deputation

Problem Statement:

A professional society is organizing a conference and needs to form a diverse deputation of 3 members.

The deputation must meet the following criteria:

  • Diversity Rule: The deputation must include at least one man and one woman.
  • Distinct Combinations: Two deputations are considered distinct if they have at least one different member.

You are given:

  • m: The number of eligible men.
  • w: The number of eligible women.

Your task is to calculate the total number of distinct ways to select a diverse deputation of 3 members, following the diversity rule.

Example:

m = 1

w = 3

There is m = 1 man available and there are w = 3 women. Label them m1, w1, w2, w3 for demonstration. There are 3 possible ways to form a diverse deputation: (m1, w1, w2), (m1, w1, w3) and (m1, w2, w3). The only other possible permutation is (w1, w2, w3), which does not include a man, so it is invalid.

ADD COMMENTlink 2 days ago admin 1.8k

Login before adding your answer.

Similar Posts
Loading Similar Posts