Hey guys ,
I applied for Sharechat SDE-1 backend role on their careers site and I got an invite for an online assessment on Hackerrank.
There were 3 questions in total . 90 minutes to solve . I didn't have to turn on my camera or microphone.
Question 1:
Given an array of bricks , you are given 2 hammers , one small and one big. The number of strikes it takes to demolish a brick using a small hammer is the weight of the brick "brick[i]". Where as when you use a big hammer you can break it in a single strike .
Say you have a brick of weight 3 , it will take you 3 strikes to break it completely using a small hammer , on the other hand it would just take a single strike with a big hammer to break it completely.
You are asked to find the minimum number of strikes it takes to demolish all the bricks in the given array "bricks" , and you are also given the number of strikes you are allowed to make using the big hammer.
Input format :
bigShots = 3
bricks = [5,2,6,8,2,4]
Output:
11
Intuition:
bricks= [5,2,6,8,2,4]
Sort the array first :
bricks = [2,2,4,5,6,8]
Be greedy and start from the right (thats where all the heavier bricks are) and strike them using big hammer.
You can break 5 , 6 , 8 using big hammer in just 3 strikes
and you can break 2, 2,4 using small hammer .
So the output is 2 + 2 + 4 + 3 = 11
Question 2:
Implement a prototype service to simplify a group of debt transactions.
There are n people with m debts amongst them where debts[i] = [from[i], to[i] , amount[i]] represents that person from[i] owes person to[i] an amount of amount[i].
Given the array of debts , find the minimum number of transactions required to clear all the debts.
Input Format:
n = 3
m = 4
debts = [[0,1,20],[1,0,5],[1,2,10],[2,0,10]]
Output:
2
Question 3:
I don't properly remember the question because I wasn't able to solve this in time but I will try to explain it using an example
given an array = [3,1,2]
Find the minimum number of changes you need to make such that the end array has :
Say , arr = [3,1,7]
Then the output is 2.
How?
We change arr[0] to -1
We don't need to change arr[1] as arr[1]=1 (condition 2)
We change arr[7] to 2
So we made 2 changes in total.
P.S : I was able to solve the first 2 questions , wasn't able to solve the 3rd completely because I spent too much time on the first 2 problems. What do you guys think my chances are of getting a call back? I don't think they'll call back :(