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

learn more… | top users | synonyms (1)

75
votes
4answers
7k views

Calculate SHA1 hash from binary and verify with a provided hash

I applied for a job and they asked me to write code with the following requirements: Get a "toolbar offer" description from http..update.utorrent.com/installoffer.php?offer=conduit. Parse the ...
66
votes
15answers
4k views

Searching an element in a sorted array

I was applying for a position, and they asked me to complete a coding problem for them. I did so and submitted it, but I later found out I was rejected from the position. Anyways, I have an eclectic ...
51
votes
16answers
6k views

Outputting the names of cars, without repetitions, with the number of occurrences in order of decreasing repetitions

A short while ago, I have submitted a coding exercise to a potential employer. The response came back the next morning and you can guess what it was from the subject of this post. I am not ...
28
votes
11answers
3k views

Searching in an array in less than O(n) time

I have an array where each element is either one less or one greater than the preceding element \$\{x_i = x_{i-1} \pm 1\}\$. I wish to find an element in it in less than \$O(n)\$ time. I've ...
24
votes
2answers
2k views

Interview screw-up after piece of asynchronous callback code

I was screwed up after submitting this piece of work. But I have no feedback to know what "BAD" things are inside this block of code. The requirements are like this: Connect to the server on a ...
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 ...
16
votes
5answers
998 views

Parse webpage and save fetched images to a directory

I had a task for a programmer position which I failed. I am a newbie programmer and I accept that. The only problem is that employer never told me what the actual problem with the code is. So maybe ...
16
votes
3answers
642 views

Rainfall Problem

About a year ago when I was applying to jobs for the first time, I had an interview at a company and they posed the following problem to me, which I preceded to bomb. A year later I actually came up ...
15
votes
4answers
2k views

Reverse a string word by word

Given an input string, reverse the string word by word. For example: Given s = "the sky is blue", return ...
14
votes
6answers
1k views

Array whose values are the product of every other integer

I was asked the following interview question over the phone: Given an array of integers, produce an array whose values are the product of every other integer excluding the current index. ...
14
votes
7answers
20k views

Finding repeating numbers in an array

I want to search through an array of n numbers and find the numbers that are repeated. So far I have this code, which does the job, but I find it to be a rather cumbersome method, but I can't seem to ...
14
votes
4answers
734 views

Modelling a Call Center

This is the requirement I have (from the book: Cracking the Coding Interview) Imagine you have a call center with three levels of employees: fresher, technical lead (TL), and product manager (PM). ...
14
votes
3answers
2k views

Overlapping rectangles

I received the following question in a technical interview today (for a devops/SRE position): Write a function which returns true if the two rectangles passed to it as arguments would overlap if ...
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 ...
13
votes
4answers
632 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 ...
13
votes
4answers
512 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 ...
13
votes
11answers
606 views

Is it better to put more logic in a for loop condition, or to use a while loop?

I had this as an interview question, and the interviewer pointed this out. Here's what I wrote: ...
13
votes
3answers
919 views

Interview Review - SOLID Principle and TDD

I had a small technical C# task using SOILD principle and TDD. But I failed to prove my coding skill through the test. Can anyone offer any small advice for me? I am really eager to learn what my ...
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 ...
12
votes
5answers
609 views

ToString() and AddString() method without using .Net Collections

I was asked to answer the following question before setting up a phone interview, but they said my code wasn't detailed enough. Question: Without using any of the .NET Collection or Linq ...
12
votes
8answers
6k views

Is my AI solution to Untrusted Game considered logical or “ethical”?

I am applying to a university to study Computational Linguistics, and as I read, it would be recommended to have a background in Artificial Intelligence. The Admission board asked me to prepare a ...
12
votes
3answers
313 views

Reversing k-sized sequences in a linked-list

Here is my solution to this problem; please be brutally honest/strict, if I would have written this code, in a 45 minute interview, what would you think? (I am aiming for Google,Facebook). Here is ...
11
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 ...
11
votes
5answers
507 views

Set matrix zeros

I solved this problem in about 11 minutes (with all 50+ test cases passed). I think most of you already know me by now, and I truly appreciate your advice, but please be brutal and judge me as if I ...
11
votes
3answers
537 views

Animated JavaScript/jQuery game

This was a code test I was asked to complete by employer, and since they rejected me, I wonder what should I have done differently. ...
10
votes
3answers
465 views

Exception handling, et al - How do I make this web downloader not “poor”?

I haven't done Java coding in years, but I thought I would give it a shot for a job interview. I have a few questions: Why is this error handling considered poor? How am I supposed to be doing it? ...
10
votes
3answers
429 views

Reversing a linked list

I implemented reversing a linked list in iterative way, just by knowing we need 3 pointers and I have never seen a code before, when I coded. I ran this code and tested it, it works fine. Even for ...
10
votes
4answers
4k views

Reverse each word of a string in C

I had this interview question like a year ago and was asked to code, on a piece of paper, how to reverse each word of a string. Since I am used to Java, I proposed the obvious answer of using split + ...
10
votes
2answers
7k views

Implementation of Trie data structure accommodating varying number of children

I've used the Trie data structure to solve the following problem: Given an array of words, print all anagrams together. For example, if the given array is {"cat", "dog", "tac", "god", "act"}, then ...
8
votes
6answers
3k views

Printing stars using nested loops

I just got back from my interview where I had to solve the following problem: Write a C++ program that prints the following pattern using nested for loops. ...
8
votes
3answers
556 views

Longest Common Prefix in an array of Strings

Please be brutal, and treat this as if I was at an interview at a top 5 tech firm. Question: Write a function to find the longest common prefix string amongst an array of strings. Time it ...
8
votes
5answers
14k views

Count the number of occurrences of a word

I was selected for the third round of MS internships for third years. We were surprisingly asked a very easy question: “Make a program that counts the number of times the WORD "a" or "A" occurs”. I ...
8
votes
2answers
88 views

Sorting and searching problem related to a group of people standing in a rectangle

Please be brutal, and let me know how I've done on this problem, provided I coded it at an interview for a top tech firm. Time it took me: 44 minutes Worst case time complexity: O(n2)? Am I right? ...
8
votes
4answers
700 views

Given two sorted arrays, add the elements of the second array into the first

In Cracking the Coding Interview by Gayle Laakmann McDowell, there's a question that asks you to write code for the following: Given two sorted arrays, A and B. Write a method merging the elements ...
8
votes
1answer
357 views

Billboard challenge algorithm

This is a problem from Interview Street in Dynamic Programming section. Billboards (20 points) ADZEN is a very popular advertising firm in your city. In every road you can see their ...
7
votes
11answers
15k views

Optimizing Java Anagram checker (compare 2 strings)

An anagram is like a mix-up of the letters in a string: pots is an anagram of stop Wilma is an anagram of ilWma I am going through the book Cracking the Coding Interview and in the ...
7
votes
5answers
3k views

Find missing number from list

I was asked a question in an interview the other day: You have an array list of numbers from 1 to 100, the problem is that one number is missing. How would you find that number? This is a mock ...
7
votes
4answers
498 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. ...
7
votes
3answers
490 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 ...
7
votes
4answers
322 views

First missing positive

As usual, please be brutally honest with your opinion of my code, and how you would judge it if I were to code this at a top-tier tech company for an interview(think Google, MSFT, Facebook, etc). My ...
7
votes
4answers
3k views

Checking if three numbers sum to a given number

I'm working on the following interview practice problem, and got the following solution, which runs in worst case n! time (best case constant), and I'm trying to ...
7
votes
3answers
301 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 ...
7
votes
3answers
1k views

Finding the minimum in a sorted, rotated array

Given an array that is first sorted non-decreasing and then rotated right by an unspecified numnber of times, find the index of its minimal element efficiently. If multiple such minimal elements ...
7
votes
3answers
269 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 ...
7
votes
2answers
206 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
469 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 ...
7
votes
3answers
4k views

Reversing every word in a string

Examples: char test1[] = " "; char test2[] = " hello z"; char test3[] = "hello world "; char test4[] = "x y z "; Results: ...
7
votes
2answers
181 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 ...
7
votes
1answer
63 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 ...
6
votes
5answers
2k views

Writing FizzBuzz

First of all, I came up with that question on SO already. But I am offered different solution which are "better" in some ways. The goal is to improve this specific version, not to create another ...