This tag is for questions that came up in an interview.

learn more… | top users | synonyms (1)

9
votes
2answers
72 views

Min triangle path - bottom-up

I got a bit intrigued with the recent question DP solution to min triangle path and after a certain chat message I decided that I wanted to implement my solution. Given a triangle, find the ...
6
votes
5answers
139 views

DP solution to min triangle path

I am studying for interviews for various companies. I wrote a solution to this problem, but if an experience programmer looks at it I am sure there are certain areas the code can be made in to a more ...
6
votes
5answers
568 views

Given a String, return a boolean if it is a number

Yesterday in an online interview, the interviewer asked me this question: If I give you a string, you have to return if a string is number or not. You are not allowed to use any parse function ...
3
votes
3answers
298 views

pyramid numbers in alternative reverse order

I was asked to write code for the below structure: 1 3 2 4 5 6 10 9 8 7 11 12 13 14 15 And I tried the below code, which works, yet I'm wondering ...
3
votes
1answer
94 views

Finding the longest unique sub-string in a string

I recently interviewed with a company for software engineering position. I was asked the question of finding the longest unique sub-string in a string. My algorithms was as follows: Start from the ...
8
votes
3answers
127 views

Basic string compression counting repeated characters

My task was to implement a method which performs basic string compression by counting sequences of repeating characters. Given "aaabbbccc" it should return ...
2
votes
1answer
85 views

How should I write function to print a singly linked list in a reverse order?

I am preparing for interview and I want to write the function in the way that the interviewers will expect me to write. This is my solution: ...
5
votes
2answers
329 views

Remove Nth Node from End of Linked List

I am solving the well known problem Remove Nth Node From End of List: Given a linked list, remove the n-th node from the end of list and return its head. Assume that n is between 0 and the ...
2
votes
1answer
79 views

Encoding and decoding exercise

I was issued the following coding challenge from a company to write an encoding and decoding function: Encoding: This function needs to accept a signed integer in the 14-bit range [-8192..+8191] ...
7
votes
2answers
112 views

Espresso Queue simulation

I was asked to do a technical test with the following specification, but my solution was rejected and I was not selected for the available position (Junior to "normal" level, with 4 days of time to ...
1
vote
2answers
45 views

Number of maximal PAIRS-values

I had an interview question like this: In a company there are different people. One can measure how well they suits for pair coding as follows: First, let us compute the PAIRS-value which ...
3
votes
1answer
135 views

Interview task to efficiently find compact representation of nodes in tree and find big O time

I recently had an interview problem where I was asked to find a compact representation of nodes in a tree. As an example, consider the following tree: ...
1
vote
1answer
131 views

Print all permutations of a given string in Java

I want to print all permutations of a given string in Java. To do this I create one auxiliary array boolean used[] to check if I have used some character or not. ...
4
votes
1answer
364 views

Print all possible combinations of size r, from an array of size n

This is my working solution for the following problem: given an array of integers of size n, print all possible combinations of size r. Before I proceed to the solution, I have the following ...
11
votes
3answers
146 views

Recursive, nested list traversal

Given a nested list of strings (which may contain other nested lists), print the contents of the list and the corresponding depth. Here is my solution: ...
29
votes
9answers
3k views

Which FizzBuzz is better, and why?

I was in an interview and the guy asked me to do the typical FizzBuzz question of printing numbers 1-100, but for each factor of 3 print Fizz, each factor of 5 print Buzz, and each factor of both ...
1
vote
3answers
189 views

Alternating split of a given singly linked list

Write a function AlternatingSplit() that takes one list and divides up its nodes to make two smaller lists 'a' and 'b'. The sublists should be made from alternating elements in the original list. ...
8
votes
2answers
226 views

Bowling game scorer

I was given a simple coding exercise as part of a job interview process, for which I received a negative review. This is the question: DiUS is starting a bowling club. To help with the club, we ...
10
votes
2answers
118 views

Finding the next number in sequence

I have a question to find the N th number in the sequence. 1 11 21 1211 111221 312211 13112221 1113213211 The next ...
8
votes
2answers
529 views

Animal choir simulator

I got a PHP developer interview test to solve for a company. I didn't get the job but I would like to know where I was wrong. Did I understand the test completely? ...
10
votes
1answer
266 views

Find the peak stock price for each company from CSV data

During the hiring process, a company gave me this test: Q) Consider Share prices for a N number of companies given for each month since year 1990 in a CSV file. Format of the file is as below ...
7
votes
3answers
301 views

Find two unique integers in sorted array

I have to write the following method: I have sorted array of integers and in this array every integer repeats twice, except two elements. I have to find these two elements. Input: 1, 1, 2, 3, 3, ...
10
votes
3answers
968 views

List all possible numbers from a given array that sums up to a given number

I have to solve the following problem: Given an array of integers and given an integer value, list all possible numbers frm the array that sums up to the given value. Example: Input: array = {1, 2, ...
6
votes
2answers
489 views

Binary Search Tree implementation using templates

I wrote this implementation using templates. It works fine and as expected. Just want to know if this can be improved. I have some specific questions too at the end. Please feel free to critique to ...
25
votes
10answers
3k views

What are some indicators that I was over-thinking my solution to this problem?

This question is a cross between career question and a code review. I was uncertain where to ask, but since there is code involved I went with CodeReview. I’m going through the process of technical ...
7
votes
2answers
699 views

Implementing division without addition, multiplication, division or subtraction - follow-up

This is a follow-up to this question: Division without using addition, multiplication or division Could you please tell me if there is better way of performing division without ...
0
votes
1answer
134 views

Division without using addition, multiplication or division [closed]

Could you please tell me if there is better way of performing division without +, * or /? ...
6
votes
1answer
124 views

Russian doll envelops

Interview question from the interwebz You have a set of envelopes of different widths and heights. One envelope can fit into another if and only if both the width and height of one envelope ...
4
votes
2answers
229 views

Finding the value 'n' in an array that has 'n' or more larger values

Given an unsorted array of integers, you need to return maximum possible \$n\$ such that the array consists at least \$n\$ values greater than or equals to \$n\$. Array can contain duplicate ...
6
votes
1answer
112 views

Flatten double-linked list

Consider this interview question: Given a Node with a reference to a child, its next, its previous, and a variable for its value (\$\frac{1}{2}\$ tree, \$\frac{1}{2}\$ doubly linked list ...
3
votes
2answers
132 views

Class that implements a queue using two stacks

I am looking for a review of my code that implements a MyQueue class which implements a queue using two stacks. ...
12
votes
6answers
2k views

Implementing a Stack in Java for Technical Interview

This code is based off the Stack implementation in Chapter 3 of Cracking The Coding Interview. I modified the code to make it compile and give me the correct output. I'd appreciate any feedback on ...
5
votes
3answers
511 views

Implementing a queue in Java for a technical interview

This code is based off the Queue implementation in Chapter 3 of Cracking The Coding Interview. I modified the code to make it compile and give me the correct ...
6
votes
1answer
94 views

Finding the sub-array with maximum sum - my slow approach

I decided to give the maximum sub-array sum problem an interesting go, however I will assure you that it doesn't perform well, and that I would never put this in production. I'd like a review on ...
13
votes
4answers
690 views

Finding the sub-array with the maximum sum - my approach

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem The basic idea here is to not loop through more things than ...
7
votes
4answers
2k views

Find the subarray with the max sum

In an interview I was asked to solve the following problem: find a subarray with max sum I have written a piece of code for the same. I need your help in reviewing this code. ...
2
votes
1answer
558 views

Simple anagram or permutation generator in Python

In preparation for a job interview I decided to try and implement the classic find all anagrams of a given string solution. I wanted to see if I could translate a javascript solution into python. This ...
13
votes
7answers
3k views

Is my solution to return kth row of the Pascal's triangle suitable for a job interview?

Question: Given an index \$k\$, return the \$k\$th row of the Pascal's triangle. For example, given \$k = 3\$, return \$[1,3,3,1]\$. Bonus points for using \$O(k)\$ space. Can it be ...
4
votes
2answers
139 views

Scalability issues, storing scores for users on a particular level for later retrieval

I recently handed in a test assignment for a job application, which I was declined, with the motivation that it had scalability issues. The test was to setup a REST-like backend for a hypothetical ...
8
votes
2answers
444 views

Missing level of technical depth (Common Ancestor)

I recently have given a coding test in a reputable IT company. There were three coding questions. They refused me by saying that as we felt they didn't demonstrate the level of technical depth ...
5
votes
2answers
482 views

Missing level of technical depth (Flatten Tree)

I recently have given a coding test in a reputable IT company. There were three coding questions. They refused me by saying that as we felt they didn't demonstrate the level of technical depth ...
5
votes
1answer
445 views

Missing level of technical depth (Recursive to Iterative)

I recently have given a coding test in a reputable IT company. There were three coding questions. They refused me by saying that as we felt they didn't demonstrate the level of technical depth ...
7
votes
4answers
308 views

Number to words in left to right direction

I have faced one logical question in an interview: If we enter a number it will convert into individual strings and display in same order. Ex: If I enter 564 ...
3
votes
2answers
128 views

Python Barcode Generator v2

This is a complete rewrite of the code posted for review in this question. The question is identical. ...
13
votes
4answers
660 views

Determining if an answer can be generated

How can I improve my code below for the following question? While it works, I am not satisfied with how it looks; I was hoping I can somehow keep it recursive, and have the ans filled up inside the ...
2
votes
3answers
329 views

Python Barcode Generator

I was asked to provide some example code for a job interview and didn't have anything to offer, so I wrote the following function. A barcode generator may seem a bit basic, but there's some logic ...
16
votes
8answers
2k views

Find all the missing number(s)

Recently I've attended an interview, where I faced the below question: Question: "There is an sorted array. You need to find all the missing numbers. Write the complete code, without using any ...
8
votes
2answers
229 views

Given a page of content, determine shortest snippet containing all search phrases (no order required)

A recruiter gave me a homework problem as a part of the recruiting process and after receiving my submission he told me that he decided not to proceed with me. When I asked for the reason, he told me ...
7
votes
4answers
999 views

Calculate final test score from a list of test results

Recently I have given an interview to a widely well-known technology firm. The first interview was general and it went well but they rejected based on some technical things. They did not mention it so ...
6
votes
2answers
166 views

Breaking of a sentence

(Method signature is given with parameters) Try to visualize me writing this code at an interview, and please be brutal while judging it. Problem: Given a string s and a dictionary of words ...