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

learn more… | top users | synonyms (1)

5
votes
2answers
203 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
56 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
91 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
votes
0answers
31 views

Singly linked list implementation and related questions [closed]

I started brushing up Data Structures and Algorithms several days ago in preparation for upcoming interviews in a few months. I began with linked lists and discovered I'm a bit rusty. With clause ...
1
vote
2answers
38 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
123 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
70 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. ...
3
votes
1answer
91 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
118 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: ...
27
votes
7answers
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
111 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
149 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
110 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
506 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
250 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
288 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
568 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
293 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
517 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
115 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
110 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
208 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
95 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
73 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
418 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
79 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
618 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
1k 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
215 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
2k 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
135 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
364 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
380 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
367 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
295 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
118 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
649 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
240 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
10answers
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
224 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
693 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
138 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 ...
7
votes
1answer
96 views

Finding the length of shortest transformation sequence from start to end

Please treat this as a interview at a top tech firm, and share your thoughts on how you think I did. Be honest, and leave no stone unturned. Problem: Given two words (start and end), and a ...
7
votes
3answers
319 views

Simplifying a path

Please be super brutal, and treat this as a top technical interview. Worst case analysis: \$O(n)\$ (please confirm) Space complexity: \$O(n)\$ Problem: Given an absolute path for a file ...
5
votes
2answers
252 views

Finding alternating sequence in a list of numbers

Please be brutal and treat this as me coding this up for an interview. A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between ...
3
votes
1answer
57 views

Grouping Anagrams

Please be über brutal, and treat this as a technical interview question. I was wondering how this function that I wrote looks like. It groups together words that have the same alphabets (i.e ...
7
votes
3answers
656 views

Find Minimum Number of coins

Please be brutal, and treat this as a top 5 technical interview. I am trying to follow Google's way of writing Java code, as per their .pdf file online of code review. (Side note: do any of you see ...
13
votes
5answers
1k views

Longest palindrome in a string

Please be brutal, and judge my code as if it was written at a top 3 tech company, straight out of college. (The method signature, and input parameter is given by the problem, so don't worry about ...