Most Asked Question Google Interview and Candidates are not able to solve

google logo
google
June 21, 20253 reads

Summary

This post describes a challenging algorithmic problem frequently asked in Google interviews, involving cost-effective operations to make integers divisible or not divisible by 3.

Full Experience

integer a,b,c,d,e given d is cost of incrementing 1 in every integer and e is cost of incrementing 1 only in any one integer u have to calculate step1 a,b,c are divisible by 3 and step 2 a,b,c are not divisible by 3 a = 1, b=2, c=3 , d=1 ,e=1 for step 1 we increment b by 1 following e cost and then increment a by 2 following 2 times e operations total cost = 3, now a,b,c are divisible by 3 for step 2 increment c by 1 following e cost, now a,b,c are not divisible by 3 answer 3,1

constraints 0<a,b,c<1000

Interview Questions (1)

Q1
Optimize Integer Divisibility by 3 with Costs
Data Structures & AlgorithmsHard

Given integers a, b, c, d, e where 'd' is the cost of incrementing 1 in every integer and 'e' is the cost of incrementing 1 only in any one integer. You need to calculate the minimum cost for two steps:

Step 1: Make a, b, c all divisible by 3. Step 2: Make a, b, c all NOT divisible by 3.

Example: a = 1, b = 2, c = 3, d = 1, e = 1

For Step 1: Increment b by 1 (cost 'e') then increment a by 2 (2 times 'e' operations). Total cost = 3. Now a, b, c are divisible by 3.

For Step 2: Increment c by 1 (cost 'e'). Now a, b, c are not divisible by 3.

Expected answer: 3, 1

Constraints: 0 < a, b, c < 1000

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!