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

learn more… | top users | synonyms (1)

4
votes
3answers
382 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 ...
11
votes
5answers
916 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 ...
8
votes
3answers
154 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 ...
5
votes
4answers
113 views

Find the sum along root-to-leaf paths of a tree

Most of you already know me, please be brutal, and treat this code as if it was written at a top tech interview company. Question: Given a binary tree and a sum, find all root-to-leaf paths where ...
3
votes
1answer
76 views

Winning Pattern Detection [on hold]

This was a question asked to me before setting up an interview. You are given a game board that contains a four by four (4x4) array of pieces. The pieces can be one of six shapes and can be one of six ...
11
votes
6answers
4k 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 ...
8
votes
2answers
75 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? ...
5
votes
2answers
45 views

Pascal triangle produced for a particular integer K

Please be brutal and let me know what you think of the code below, if written at an interview. Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = ...
2
votes
1answer
112 views

Simple application for finding local restaurants

I was asked to create a test APK file by a company HR when I applied for an Android developers job, Specification: The goal is to develop a simple application which finds the local restaurants. ...
12
votes
5answers
559 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 ...
2
votes
2answers
38 views

ZigZag order of a tree traversal

Please let me know your thoughts on the code below, please be brutal. Here is the question I solved: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left ...
5
votes
1answer
70 views

Searching in a sorted 2D matrix

If I was at an interview, and wrote this code, what would you think? Please be brutal. Time it took to wrote it: 13 minutes Problem: Write an efficient algorithm that searches for a value in an ...
5
votes
3answers
87 views

Use up all characters to form words

Task: Given a dictionary of words, and a set of characters, judge if all the characters can form the words from the dictionary, without any characters left. For example, given the dictionary ...
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. ...
6
votes
2answers
122 views

Calculate Suitability Score program

I am a beginner in C++ and learning from textbook. I find it hard to jump into oops concepts as I have used C a lot. Here is an interview question I came across: Problem Statement Our ...
11
votes
5answers
462 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 ...
15
votes
4answers
1k 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 ...
6
votes
3answers
241 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 ...
12
votes
3answers
220 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 ...
6
votes
2answers
196 views

Add one to a number represented as an array of digits

I submitted this problem for an interview, and I was wondering if I could have done better. My solution works, and I solved in about 12-15 minutes. I feel like I did a bad job with the code. Please ...
14
votes
4answers
669 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). ...
6
votes
3answers
114 views

How to extract elements from multiple sorted list efficiently?

Problem Statement:- I was ask this interview question recently.. I was able to come up with the below code only which runs in O(k log n)- Given k <= n sorted arrays each of size n, there exists ...
13
votes
3answers
677 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 ...
5
votes
3answers
281 views

Client Sends XML, Server Parses XML, Queues Up and Executes Commands

I recently had a Java interview where I was asked to write a client-server application. I don't code primarily in Java, but with my preliminary Java knowledge, I thought I built a reasonable working ...
6
votes
2answers
165 views

Spring password validator library

I recently got rejected at a job interview for submitting this: https://bitbucket.org/gnerr/password-validator The interviewer asked for a password validation library that was configurable via ...
7
votes
4answers
2k 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 ...
1
vote
1answer
132 views

Printing numbers in lexicographic order

I saw this problem posted as an interview question asked at Bloomberg: Given an integer N, print numbers from 1 to N in lexicographic order. Restriction. One cannot use strings or characters. ...
6
votes
3answers
128 views

HTTP scraper not clean and straightforwardly coded?

A job application of mine has been declined because the test project I submitted was not coded in a clean and straightforward way. Fine, but that's all the feedback I got. Since I like to ...
15
votes
3answers
446 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 ...
3
votes
1answer
145 views

Clockwise and counterclockwise spiral matrix traversal

An interviewer asked me to write clean Java code for clockwise and counterclockwise spiral matrix traversal. e.g. {{1,2,3}, {7,8,9}} becomes ...
2
votes
3answers
195 views

What are the problems with this method?

I received this question at a C++ programming interview: ...
1
vote
1answer
113 views

Spell check interview problem in Bash

Thanks for taking the time to read this. I submitted a code screening for a company I really wanted to work for and spent a decent amount of time on their programming assignment. Pretty bummed when ...
5
votes
3answers
899 views

Find elements occurring even number of times in an integer array

I came across an interview question, which is like this: You have an array of integers, such that each integer is present an odd number of time, except 3 of them. Find the three numbers. I tried ...
3
votes
1answer
289 views

Printing a Binary Tree top-down (column wise)

We have a binary tree, suppose like this: 8 / \ 6 10 / \ / \ 4 7 9 12 / \ 3 5 We have to print this binary tree in top-down ...
26
votes
11answers
3k views

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

I've an array where each element is either one less or one greater than the preceding element. I've to search an element in it in less than O(n) time. I've implemented it like this: ...
4
votes
2answers
694 views

Printing out a binary tree level by level

Below is my implementation for an interview question of printing a binary tree level by level. I've also included some methods for creating a binary tree from a vector in my solution. Please review ...
6
votes
2answers
302 views

Generating a list of alternatively positioned odd and even number out of an array of unsorted integers

I had an half an hour interview with Microsoft for an intern position. I was asked to generate a list of alternatively positioned odd and even number out of an array of unsorted integers. I guess it ...
4
votes
2answers
187 views

Merge two sorted arrays together

Please review my answer for this interview question: ...
2
votes
3answers
247 views

strstr implementation

Please review my strstr implementation. This is an interview question that does not allow the use of strlen(). Is there a better way than using a boolean below? ...
4
votes
2answers
346 views

How can I improve this simple calculator interview question?

Question: Simple Calculator Input loaded from file. Instructions can be any binary operators. Ignore math precedence. Last input is apply and a number e.g. "apply 5". Calc is then ...
4
votes
2answers
539 views

Determining possible triangle from lengths of line segments [closed]

This Codility challenge is to take an array of integers representing lengths of line segments, and determine whether or not it is possible to choose three distinct segments to form a triangle. (The ...
2
votes
2answers
1k views

Fish Food Chain O(N)

I understand that if you don't know the trick, it's not easy create a solution with a complexity of O(N). However, I would like to ask you how to solve this tricky question: You are given two ...
2
votes
1answer
110 views

Please critique my C++ code for some classic programming interview questions

I'm going to post some of my solutions to common interview questions. I would love it if you could critique me from a C++ purist's standpoint. Also, tell me if there's a better algorithm for each one ...
2
votes
5answers
227 views

Optimal code without using for, while and if

I presented a code solution to a startup as part of their interview polity. The problem statement is to find the frequency of words occurring in a sentence. I got the code rejected saying, ...
0
votes
2answers
495 views

Run-length encoding using C / C++

This is my first post on Code Review. I have already asked this question on Stack Overflow and was asked to post it here. Here is the link. Recently I was asked in an interview to convert the string ...
4
votes
2answers
606 views

iOS: Code review of MasterViewController

I plan on including this work in a portfolio. Question: Will this code get me hired or laughed at? More Specifically: How would you rate the general complexity of the code? How bad does the code ...
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 ...
1
vote
2answers
584 views

Detect if linkedlist contains a loop

Following is a code to detect a loop in a linkedlist. This question is prepared strictly for interview purposes. This code has been modelled as per Linkedlist.java How to decide if a function like ...
3
votes
2answers
262 views

Review of object-oriented skills with War game

Here are my code samples: https://github.com/arthaeus/war This particular sample is the card game 'War'. The interviewer off-handedly asked me: "what if I wanted to play War with an Uno deck of ...
71
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 ...