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

Posted
21 Jun 2025
367 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.

How it went

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

Questions asked (1)

  1. 01

    Optimize Integer Divisibility by 3 with Costs

    Data Structures & Algorithms · Hard

    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

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Google recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

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