Append and Delete

Solutions The challenging part of this exercise is how to handle operations in excess. If a string is empty, we can consume as many operations we want (as the problem specifies). So, the easy case is when we have a number of operations that is greater than the sum of length of both strings. In this case the solution is “Yes” because we can just remove all the characters from one, consume excess operations by repeatedly performing the second operation from the empty string, and finally appending the other characters. [Read More]
string  math 

Circular Array Rotation

Solutions You can actually rotate the array: in Javascript (by Alessia Bragagnolo) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 function circularArrayRotation(a, k, queries) { let result = []; while (k > 0) { let tmp = a.pop(); a.unshift(tmp); k--; } for (let i = 0; i < queries.length; i++) { result.push(a[queries[i]]); } return result; } But… we don’t really need to rotate the array: [Read More]
math 

Fair Rations

You are the benevolent ruler of Rankhacker Castle, and today you’re distributing bread. Your subjects are in a line, and some of them already have some loaves. Times are hard and your castle’s food stocks are dwindling, so you must distribute as few loaves as possible according to the following rules: Every time you give a loaf of bread to some person , you must also give a loaf of bread to the person immediately in front of or behind them in the line (i. [Read More]
math  ad hoc 

Product of Array Except Self

Given an array of \( n \) integers where \( n > 1 \), \( nums \), print an array \( output \) such that \( output[i] \) is equal to the product of all the elements of \( nums \) except \( nums[i] \).

Solve the problem in \( O(N) \) without using division.

[Read More]

Restaurant

Solutions We have to cut a rectangular bread having size \(l * b\) into squares of equal dimension such that no piece of original bread is left over. So we have to make cuts only vertically or horizontally. Hence we can conclude that if the length of a side of the square is \(a\), both \(l\) and \(b\) has to be divisible by \(a\). In addition, \(a\) has to be as large as possible. [Read More]
math