## keviIma

BAN USER- 1of 1 vote

AnswersGiven a grid M x N cells having weight in each cell(any integer),

- keviIma in United States

For every path from TOP-LEFT to BOTTOM-RIGHT, find the minimum weight you come across.(Minimum per path.)

Now from all those minimum weights, find the Maximum.

You can move in all 9 directions.

Is this a trick question?| Report Duplicate | Flag | PURGE

Amazon - 0of 0 votes

AnswersGiven an arbitrary tree remove nodes which have data value 0.

- keviIma in United States

As it stats arbitrary tree, I assumed n-ary tree.| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 0of 0 votes

Answers* Build Offices

- keviIma in United States

A company wants to develop an office park in an area that has been divided up into a grid where each cell represents a potential building lot. The goal is for the furthest of all lots to be as near as 1 possible to an office building. Determine the building placement to minimize the distance the 0 most distant lot is from an office building. Movement is restricted to horizontal and vertical, i.e. diagonal movement is not allowed.

For example, there are n = 3 office buildings to build on a grid that is w = 4 lots wide and h = 4 lots high. An optimal grid placement sets any lot within two units distance of an office building. In the distance grid below, offices are cells at distance 0.

1 0 1 2

2 1 2 1

1 0 1 0

2 1 2 1

That represents one optimal solution among several, this array rotated for example.

The function must return an integer that denotes the maximal value among shortest distances to the closest office for each cell.

findMinDistance has the following parameter(s): w: an integer, the width of the grid h: an integer, the height of the grid n: an integer, the number of buildings to place

Constraints:

wxh <= 28| Report Duplicate | Flag | PURGE

- 1of 1 vote

AnswersGiven a number N, Assume a lexicographical ordered 1 to N numbers.

- keviIma in United States

Given array consisting of indices, return the array with numbers at that positions in the lexicographically sorted array of [1 to N].

follow up: Do not use Extra memory.

Expected Runtime = O( N * log k) or O(N)

N = total numbers, (1 to N)

k = Number of queries

Example:

N = 12

lexicographical ordered array = [1,10,11,12,2,3,4,5,6,7,8,9]

Query = [1 , 4]

return = [10, 2]| Report Duplicate | Flag | PURGE

- 1of 1 vote

AnswerThere are A cities numbered from 1 to A.

- keviIma in United States

You have already visited M cities, the indices of which are given in an array B of M integers. If a city with index i is visited, you can visit either the city with index i-1 (i >= 2) or the city with index i+1 (i < A) if they are not already visited. Eg: if N = 5 and array M consists of [3, 4], then in the first level of moves, you can either visit 2 or 5. You keep visiting cities in this fashion until all the cities are not visited.

Find the number of ways in which you can visit all the cities modulo 10^9+7

N = 5

Visited = [2, 5]

Number of ways = 6

1 -> 3 -> 4

1 -> 4 -> 3

3 -> 4 -> 1

4 -> 3-> 1

3 -> 1 -> 4

4 -> 1 -> 3| Report Duplicate | Flag | PURGE

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

You have to place n offices in such a way that for any non-office cell, it's nearest as possible. In short among all combinations of placing n offices, find min(max(office_distance_from_cells) of all combinations)

- keviIma December 31, 2018