Skip to main content

Flipkart

Flipkart OA 2023 - Coding Friends


Sam and Kelly are programming buddies. Kelly resolves to practice more as Sam is initially ahead. They each solve a certain number of problems daily. Your task is to find the minimum number of days for Kelly to have solved more problems than Sam. If Kelly cannot surpass Sam, return -1.

Function Description:

Complete the function minNum:

int minNum(int samDaily, int kellyDaily, int difference);

Parameters:

  • samDaily: The number of problems Sam solves in a day.
  • kellyDaily: The number of problems Kelly solves in a day.
  • difference: The number of problems Sam is ahead to begin with.

Output:

Return the minimum number of days for Kelly to surpass Sam. If Kelly can never surpass Sam, return -1.


Example

Input:

samDaily = 3
kellyDaily = 5
difference = 5

Output:

3

Explanation:

Example:

  • Sam Daily: 3
  • Kelly Daily: 5
  • Difference: 5

Initially, Sam has solved difference problems more than Kelly. Each day, they solve samDaily and kellyDaily problems respectively.

  • Day 1:
    • Sam Solved: difference + samDaily = 5 + 3 = 8
    • Kelly Solved: kellyDaily = 5
  • Day 2:
    • Sam Solved: 8 + 3 = 11
    • Kelly Solved: 5 + 5 = 10
  • Day 3:
    • Sam Solved: 11 + 3 = 14
    • Kelly Solved: 10 + 5 = 15

Since Sam is 5 problems ahead of Kelly and they solve 3 and 5 problems a day respectively, Sam will be ahead by only 3 after the first day, 1 after the second, and Kelly will surpass Sam on Day 3.