## Backend Developer Interview Questions

- 0of 0 votes
Given a remote having 0-9 digits, plus button (to increase channel), minus (to decrease) and previous channel button (to go to previous channel). We were given 2 numbers stating start and end channel number and an array having various channel numbers. The task was to go to all channel numbers given in array with minimum number of clicks.

- 3of 3 votes
Apple phone interview

Given an API to find all IPv4 addresses in a log file, find all IPs that occurred only once.

Follow-up: What if the log comes from a data stream.

Follow-up: If the machine has 4GB RAM, is there going to be a problem?

- 0of 0 votes
write bash code to determine if the first number in the string is greater than 1000

STR="count ------- 43952 (1 rows)"

- 0of 0 votes
There is 3D space, limited with a cube, with edge=2000.

The center of coordinate system is point (0; 0; 0), so the maximum/minimal coordinate value is 1000/-1000.

There are 10000 points generated with discrete uniform distribution inside of K spheres, located in the cube.

Radius (R) of each sphere is 250.

Centers of spheres are located at the distance of not less than 2*R.

It is required to determine which point related to which sphere.

Input: array of 10000 structures, like:

struct Point {

int number;

int x;

int y;

int z;

}

where number is unique id of the point, x,y,z - it's coordinates.

Output:

array of 10000 structures, like:

struct Point {

int number;

int cluster_id;

}

where cluster_id is unique cluster id of a sphere that point belongs to.

Initially I considered a following solution:

1) Find Euclidian distance for each point from center of coordinates (0;0;0) to point's coordinates.

2) Sort this array of distances in descending order.

3) Get the point from the sorted array of distances and put in a new Set of Cluster Maximals.

4) Compare following point from the array to each value from the Set of Cluster Maximals (initially 1 value).

If it's Euclidian distance less than or equal to 2*R, then

mark this point as belonging to Kth cluster (range=1..N), otherwise add the point to the Set of Cluster Maximals.

5) Repeat step 4.

Two concerns I have:

1) There is an issue that my algorithm would work only in case if Claster Maximals are located on the surface of the spheres.

2) Plus, according to the task requirements, there could be the case when 2 spheres can have 1 and only common point.

I think in case if point belongs to 2 spheres, it is ok to mark it with cluster_id of any of these 2 shperes.

Could you please provide a proper solution to the task?

- 1of 3 votes
Given array of length n, having element 0 to n-1.

you are allowed to swap adjacent element only if Absolute difference of two element is equal to 1.

Is it possible to sort array.

If yes print sorted output.

- -1of 1 vote
--

- 0of 0 votes
1) Given a file containing lines of chars, find if it contains "aaaaab\naaaaa" string pattern. Need to return true only if contains the EXACT pattern specified (observe the new line character).

2) How do you differentiate between actual new line and the new line character?

3) what if the file is way too big to bring it all in memory?

- 1of 1 vote
/**

* Given a nested list of integers, returns the sum of all integers in the list weighted by their REVERSED depth.

* For example, given the list {{1,1},2,{1,1}} the deepest level is 2. Thus the function should return 8 (four 1's with weight 1, one 2 with weight 2)

* Given the list {1,{4,{6}}} the function should return 17 (one 1 with weight 3, one 4 with weight 2, and one 6 with weight 1)`*/ public int reverseDepthSum (List<NestedInteger> input) { // implementation here }`

- 0of 0 votes
`import java.time.Duration; import java.time.LocalTime; import java.util.List; import java.util.Map; // Your goal is to write business logic for a very simple Restaurant booking system // You are encouraged to refactor exisiting code, create other classes, write helper methods etc // You also need to make sure that the implementation works correctly class Reservation { public String name; public int partySize; public LocalTime startTime; } class Table { public int tableNumber; public int maxPartySize; } class Restaurant { public List<Table> tables; public LocalTime openTime; public LocalTime closeTime; public Map<Integer, Duration> reservationDurationsPerPartySize; // Returns a Table if Reservation could be booked, null otherwise // Booking rules: // 1) Reservation could be made only when the Restaurant is open. // 2) Only one Reservation can be seatted a Table at any time. // 3) Reservation can be seatted only at a Table of the same or a bigger size. // 4) Reservation should stay on the same Table for the whole Duration. // 5) Reservation Duration is determined by PartySize. public Table bookReservation(Reservation reservation) { //TODO: } }`

- 0of 0 votes
Given set of N number of points/Co-ordinates[(x1,y1),(x2,y2), (x3,y3), (x4,y4), (x5,y5), etc] find if any of them form square.

- 0of 0 votes
1) Finish writing the below method: bookReservation(Reservation reservation)

2) You are free to add, modify, etc the following classes and method`import java.time.Duration; import java.time.LocalTime; import java.util.List; import java.util.Map; // Your goal is to write business logic for a very simple Restaurant booking system // You are encouraged to refactor exisiting code, create other classes, write helper methods etc // You also need to make sure that the implementation works correctly class Reservation { public String name; public int partySize; public LocalTime startTime; } class Table { public int tableNumber; public int maxPartySize; } class Restaurant { public List<Table> tables; public LocalTime openTime; public LocalTime closeTime; public Map<Integer, Duration> reservationDurationsPerPartySize; // Returns a Table if Reservation could be booked, null otherwise // Booking rules: // 1) Reservation could be made only when the Restaurant is open. // 2) Only one Reservation can be seatted a Table at any time. // 3) Reservation can be seatted only at a Table of the same or a bigger size. // 4) Reservation should stay on the same Table for the whole Duration. // 5) Reservation Duration is determined by PartySize. public Table bookReservation(Reservation reservation) { //fill this method }`

- 2of 2 votes
Print the longest path from root to leaf in a Binary tree (Basically the nodes that lie on the height path).

- 0of 0 votes
2.{{ Query the sum of all the data values in a given rectangle (x1,y1) ~(x2, y2).

int querySum(int x1, int y1, int x2, y2) {}}}

- 0of 0 votes
{{Given a two dimensional grid that stores data as integers with the size of N*M, implement write and query functions which supports:

1. Write the given value to designated coordination (x, y).

void write(int value, int x, int y) {}

}}

- 0of 0 votes
http://www.buycakeonline.in/corporate-cakes.php

- 0of 0 votes
Given an array of integers where size of array can be large. Find if it is possible to make all elements of given array equal by multiplying elements with one or more input prime numbers.

e.g.

arr = 50, 200

primes to use = 2, 3

so possible by multiplying 50 by 2 * 2

e.g.

arr = 3, 5

primes to use = 7

not possible

- -3of 3 votes
Given a number n.find (l X b) dimension such that it is maximally close .

E.g:--

12---o/p->4X3 not 6X2

13---o/p->5X3 // as it is close

- 1of 1 vote
given a LinkedList like 1->2->3->4->5->6

Modify it as:

1->6->2->5->3->4

- 0of 0 votes
You have table defining meta data for all tables in your system

col name | table name | primary key| foreign key|

design a algorithm to generate sql dynamically based on column selection.

- 0of 0 votes
Using the following:

public static Func<int, int> Y(Func<Func<int, int>, Func<int, int>> f)

{

return x => f(Y(f))(x);

}

Create a Func<int, int> which computes the n-th fibonacci number using only anonymous lambdas.