## twinmind

BAN USER- 1of 1 vote

AnswersYou have a string of numbers, i.e. 123. You can insert a + or - sign in front of ever number, or you can leave it empty. Find all of the different possibilities, make the calculation and return the sum.

- twinmind in United States

For example;

+1+2+3 = 6

+12+3 = 15

+123 = 123

+1+23 = 24

...

-1-2-3 = 6

...

Return the sum of all the results.| Report Duplicate | Flag | PURGE

Facebook Software Developer Algorithm - 0of 0 votes

AnswersA new airline company is setting up operations and needs your help! They want to optimize their routes so as to cover a full list of cities, wile minimizing the cost of their operations.

- twinmind in United Kingdom

You are provided with the number of N cities and with the costs of operating flights between some of the cities.

Can you design an algorithm that will return the list of routes that cover all the N cities at the minimum operational cost?

Assumtions:

1. not all direct routes between cities are possible, but all cities can be reached either directly of via intermediate cities. You are provided with the complete set of routes that are possible as input to your algorithm.

2. the costs of operating a route from any city to any other directly connected city is known and unique (i.e., no two costs between direct routes are the same)

3. the cost of operating a route from city X to city Y is equal to the cost of operating the route from city Y to city X

Your algorithm will get as input from stdin the following:

1. on the first line, the number of cities N

2. on the second line, the total number of possible routes K

3. on the subsequent K lines, the possible routes between cities and their operational cost, separated by spaces. Cities are integer numbers from 0 to N-1. costs are floats.

The output of your algorithm should be the list of routes chosen to be operated at the minimum cost, one route per line. After the list of routes, on the final line the total cost of operating all chosen routes should be printed.

What is the time complexity of the algorithm you've created?

Example:

Input

8

16

4 5 0.35

4 7 0.37

5 7 0.28

0 7 0.16

1 5 0.32

0 4 0.38

2 3 0.17

1 7 0.19

0 2 0.26

1 2 0.36

1 3 0.29

2 7 0.34

6 2 0.40

3 6 0.52

6 0 0.58

6 4 0.93

Output

0 7 0.16

2 3 0.17

1 7 0.19

0 2 0.26

5 7 0.28

4 5 0.35

6 2 0.40

1.81| Report Duplicate | Flag | PURGE

Skyscanner Software Engineer Algorithm - 0of 0 votes

AnswersYou are given as input on stdin the number of employees in a company and their direct line management relations between each other. Each person in the company can directly line-manage maximum 2 other employees. The input from stdin has the following format:

- twinmind in United Kingdom

1. on the first line, the number of employees

2. on the subsequent lines, the line management relations in the format «EmployeeM EmployeeN» - meaning EmployeeM manages EmployeeN (names are without spaces and spaces are used to separate the two names).

The input is correct (there are only direct management relations, no cycles).

For simplicity, the first line after the number of employees always contains the manager at the top of the hierarchy.

Write a program that reads the input file and then prints out the employees per level, in order of their importance (i.e. hierarchy):

Example:

Input:

6

Jon Mark

Jon David

Mark Paul

Paul Lee

Paul Steve

Output:

Jon

Mark David

Paul

Lee Steve

Input:

7

Jon Lee

Lee Paul

Paul Mark

Paul David

Lee Steve

Steve Mat

Output:

Jon

Lee

Paul Steve

Mark David Mat| Report Duplicate | Flag | PURGE

Skyscanner Software Engineer Algorithm

Hi guys, thanks for all the answers. I was able to produce brute force solution by calculating and adding powers inside the loop without bit manipulation but my solution didn't pass timing tests, correctness tests were ok.

Is it something obvious that if i is some power of two and you do i << 1, then power gets increased by 1? It looks very elegant but I have no idea how you come up with this solution.

Rep

Rep**merrittmonique9**, Android Engineer at AMDI am Monique and working in high court from last 20 years.Handel many cases in my career.Build and ...

RepI am Susan From Wasilla USA. and my strong interest in yoga and reading historical books. I have a large ...

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

Open Chat in New Window

I guess it's not optimal that we need number of FOR loops equal to the number of positions in input integer, it is O(3^N) where N is number of positions in incoming integer and 3 is number of operators, in our case "+", "-" and "".

- twinmind March 04, 2017Also when we have +1 in the beginning of expression it's the same as just 1, so we don't need to exclude expressions starting with simple 1.