## Computer Science Interview Questions

- 0of 0 votes

AnswersGiven two strings, A and B, of equal length, find whether it is possible to cut both strings at a common point such that the first part of A and the second part of B form a palindrome.

- nemishsangani96 March 23, 2019 in India

Extension1. How would you change your solution if the strings could be cut at any point (not just a common point)?

Extension2. Multiple cuts in the strings (substrings to form a palindrome)? Form a palindrome using a substring from both strings. What is its time complexity?| Report Duplicate | Flag | PURGE

Algorithm Coding Computer Science Data Structures Dynamic Programming String Manipulation - 0of 4 votes

AnswersYou have L, a list containing some digits (0 to 9). Write a function answer(L) which finds the largest number that can be made from some or all of these digits and is divisible by 3. If it is not possible to make such a number, return 0 as the answer. L will contain anywhere from 1 to 9 digits. The same digit may appear multiple times in the list, but each element in the list may only be used once.

- Parth Patel February 21, 2017 in United States

{{

Test cases

==========

Inputs:

(int list) l = [3, 1, 4, 1]

Output:

(int) 4311

Inputs:

(int list) l = [3, 1, 4, 1, 5, 9]

Output:

(int) 94311

}}

My Solution:

{{

package com.google.challenges;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Collections;

public class Answer {

public static int answer(int[] l) {

// Your code goes here.

ArrayList<Integer> list0 = new ArrayList<>();

ArrayList<Integer> list1 = new ArrayList<>();

ArrayList<Integer> list2 = new ArrayList<>();

int sum =0;

Arrays.sort(l);

for(int i = 0; i<l.length; i++){

if(l[i] % 3 == 0){

list0.add(l[i]);

}else if(l[i] % 3 == 1){

list1.add(l[i]);

}else{

list2.add(l[i]);

}

sum += l[i];

}

if(sum%3==0){

StringBuilder strNum = new StringBuilder();

for(int i = l.length-1; i >= 0; i--)

{

strNum.append(l[i]);

}

return Integer.parseInt(strNum.toString());

}else if(sum%3 == 1){

if(list1.size()>0){

Collections.sort(list1);

list1.remove(0);

}else if(list2.size() >= 2){

Collections.sort(list2);

list2.remove(1);

list2.remove(0);

}else{

return -1;

}

}else if(sum%3 == 2){

if(list2.size()>0){

Collections.sort(list2);

list2.remove(0);

}else if(list1.size() >= 2){

Collections.sort(list1);

list1.remove(1);

list1.remove(0);

}else{

return -1;

}

}

list0.addAll(list1);

list0.addAll(list2);

StringBuilder strNum = new StringBuilder();

Collections.sort(list0);

for(int i = list0.size()-1; i >= 0; i--)

{

strNum.append(list0.get(i));

}

return strNum.length() > 0 ? Integer.parseInt(strNum.toString()) : -1;

}

}

}}

But here I am able to pass 4 test cases out of 5. Therefore I am looking for scenario which is left to check.

Can someone help me?| Report Duplicate | Flag | PURGE

Google Software Engineer Google FooBar 24x7 Google chrome technical support number 1-888-201-2039 Arrays Computer Science Java Problem Solving - 0of 0 votes

AnswersWe tend to use computer to solve practical problems that actually earns or save dollars. Here is something that happens across the stock exchanges : people buy and sell stocks.

- NoOne October 15, 2016 in India

We generally use automated intelligent systems to buy and sell stocks. That part is too much mathematics, and beyond scope of this interview. There is another part. Suppose the system issues a buy order : buy 1000 Microsoft stock. Now, there are more than 1 ( in fact 10 ) active exchanges from where we can buy MSFT. There is a slight price delta, which keeps changing over time. There is another problem. In each stock exchange, prices are stacked, that is :

1. For first 100 stocks prices are 55$.

2. Next 200 stocks, prices are 55.2$.

... etc, and you got the idea. Even this stacks are changing over time.

Thus, here is the problem to solve. Design and implement a system such that one can buy n stocks with minimal price.

Also, in the same spirit, the same system should be able to sell n stocks with maximum payoff possible.

This is a non trivial problem, for Quant systems.

There are always k no of exchanges to hit.| Report Duplicate | Flag | PURGE

Goldman Sachs Software Engineer / Developer Algorithm Cache Computer Architecture & Low Level Computer Science Distributed Computing Large Scale Computing Math & Computation Software Design - 0of 0 votes

AnswersAs you know, Computers were invented to solve practical business problems, we tend to ask practical applied questions. One of the key areas where we want to apply computers is simulation. As most of the people working in software are Engineers, here is the problem. It is called 3 body problem.

- NoOne October 15, 2016 in India

3 Bodies with masses [ m1, m2, m3 ] are initially positioned in the 3 points in the space, thus, having positions [ P1, P2, P3 ].

Observe that each Pi is nothing but [ xi, yi, zi ].

Once the initial condition is set, definitely gravity would work and they would start falling against each other. Write code to simulate this problem. Imagine G, the constant of gravity as 1.

How do you go about simulating it?

Hint : feynmanlectures.caltech.edu/I_09.html see 9.5

Face to face. Pen and Paper. Panel Interview, 2 person Panel. 60 Minutes. For Engineers only, was specifically told about it.| Report Duplicate | Flag | PURGE

Software Developer Algorithm Computer Science Graphics Math & Computation Programming Skills - 0of 0 votes

AnswersNone actually understands how garbage collection works, albeit people ask this in the interviews. Nonetheless, we are going to ask you something very similar. Here is the problem.

Take an array of bytes, perhaps 1MB in size.

Implement these two operations:`ptr_structure = alloc ( amount_of_storage ) freeed = free ( ptr_structure )`

Now, here is your problem. alloc must allocate contiguous storage. If it is not possible, you need to compact ( defragment ) memory. So, you need to implicitly write a :

`defragment() // defragments memory`

Worse is coming. Even imagining you have written a stop the world defragmenter, after you reallocate, how the ptr_structures would actually work?

- NoOne October 14, 2016 in India

Solve this whole problem.

Time allocated was 1 hour. Face to face, panel with 2 interviewers.| Report Duplicate | Flag | PURGE

SDET Algorithm Assembly Computer Architecture & Low Level Computer Science Data Structures - 0of 0 votes

AnswerI was asked the following question. Design a high throughput system where it is possible for users to transfer money from one account to other on

- bappai.mukherjee April 30, 2016 in United States

a) single thread

b) multiple thread.

I think the solution with mutex is a bad idea and making the whole thing run within the critical section. Other alternatives are appreciated.| Report Duplicate | Flag | PURGE

Computer Science - 0of 0 votes

AnswersStanford has to select a team of dodgeball players from its class of 2013. There are n students in the class and each student is identified by his/her student ID, which is between 1 and n. The coach has to select K players out of these n students for his team. But there is a twist, if among the K dodgeball players, a player's ID number evenly divides another player's ID number, then there is a high chance of them getting into a fight. The coach will do his best to select the K players so that no pair of players among them will want to fight one another. But if the game turns out to be very popular, this becomes impossible. Complete the function dodgeBall to return the minimum size of K at which it becomes impossible to choose a dodgeball team that has no fighting?

- vick4523zf March 22, 2016 in United States

Input Format:

One line of text, containing the size of the class of 2013, n

Constraints:

1 <= n <= 5,000,000,000

n is guaranteed to be an even number

Output Format:

The minimum size of K that guarantees the existence of 2 players who fight with each other in any K-sized subset of the class.

Sample Input:

4

Sample Output:

3

Explanation:

If the team = {1,2,3}: 1&2 or 1&3 can fight with each other

If the team = {1,3,4}: 1&3 or 1&4 can fight with each other

If the team = {2,3,4}: 2&4 can fight with each other

If K=2, then the teams {3,4} or {2,3} will have no fights. So 3 is the smallest value of K for which any K-sized team, must include a fighting pair.

Sample Input:

2

Sample Output:

2

Explanation:

The team = {1,2}: 1&2 can fight with each other| Report Duplicate | Flag | PURGE

Twitter Software Engineer Intern Algorithm C++ Computer Science - 0of 0 votes

Answer1) What is transaction

- dlyakolesa January 27, 2016 in United States| Report Duplicate | Flag | PURGE

Linkedin Software Engineer Computer Science

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

Open Chat in New Window