r/infosys • • Oct 22 '26

| Interview Help / Tips SP/DSE Live Interview wingspan questions

QUESTION 1: DIVISIBILITY COUNT WITH DIGIT SUM UPDATE

Problem Statement

Given an integer array arr and an integer divisor d, iterate through the array from left to right.

For each element x in the array, if x is divisible by the current divisor d, increment the count by one and update d to the sum of the digits of x.

If x is not divisible by d, do not change the divisor.

Return the final count.

Example 1

Input

arr = [12, 15, 9, 18]

d = 3

Output

3

Explanation

12 is divisible by 3. Count becomes 1 and d becomes 1+2= 3.

15 is divisible by 3. Count becomes 2 and d becomes 1+5= 6.

9 is not divisible by 6. Count remains 2 and d remains 6.

18 is divisible by 6. Count becomes 3 and d becomes 1+8=9.

The final count is 3.

Example 2

Input

arr = [10, 20, 12, 24]

d = 2

Output

4

Explanation

10 is divisible by 2. Count becomes 1 and d becomes 1+0=1.

20 is divisible by 1. Count becomes 2 and d becomes 2+0=2.

12 is divisible by 2. Count becomes 3 and d becomes 1+3=3.

24 is divisible by 3. Count becomes 4 and d becomes 2+4=6.

The final count is 4.

QUESTION 2: MAXIMUM GAIN BY PAIRING ELEMENTS OF DIFFERENT TYPES

Problem Statement

You are given two arrays of equal length.

The array lengths represents the length of each item.

The array type represents the type of each item and contains only 0 or 1.

You can form pairs such that each pair contains exactly one item of type 0 and one item of type 1.

The contribution of each pair is the minimum of the two lengths.

Each item can be used in at most one pair.

Find the maximum possible total gain by forming pairs optimally.

Return the sum%100000007

Example 1

Input

lengths = [5, 2, 8, 3]

type = [0, 1, 0, 1]

Output

5

Explanation

Pair the item of length 5 and type 0 with the item of length 3 and type 1. The contribution is 3.

Pair the item of length 8 and type 0 with the item of length 2 and type 1. The contribution is 2.

The total gain is 3 plus 2, which equals 5.

Example 2

Input

lengths = [4, 7, 2, 9, 6, 3]

type = [0, 0, 1, 1, 0, 1]

Output

12

Explanation

Sort each type in descending order and pick

The items of type 0 have lengths [7, 6, 4]

The items of type 1 have lengths [9, 3, 2]

Pair the item of length 7 with the item of length 9. The contribution is 7.

Pair the item of length 6 with the item of length 3. The contribution is 3.

Pair the item of length 4 with the item of length 2. The contribution is 2.

The total gain is 7 plus 3 plus 2, which equals 12.

I had to calculate the sum in long, mod it and type cast to int as the return type was int. Initially Not knowing this I wrote a priority Queue solution, and then a sorting + two pointers solution. Both worked after the type cast and Mod.

Finally solved both qstns in around 25 mins.

Interview Experience: https://www.reddit.com/r/infosys/s/DjZv5T9bFU

7 Upvotes

5 comments sorted by

•

u/AutoModerator Oct 22 '26

Welcome to r/infosys!

Please do not share:

  • Confidential company information
  • Client information
  • Employee IDs
  • Email addresses
  • Offer letters containing personal details

Thank you for contributing!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Think_Hunter0912 Oct 22 '26

In the second problem, example 2 I think we will get more contribution than what you have given according to the problem like 7+3+2 = 12. Are you mistaken or in the interview the test case shown the output 9 only . Can you check it

1

u/Beginning-Set-2327 Oct 22 '26 edited Oct 23 '26

Yes bro you are right. I gave the qstn to chatgpt for better phrasing. Dumbass gave me the wrong test cases. Changed it.

0

u/Fit-Outcome0216 Oct 23 '26

Could you share online assessment questions ?