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

learn more… | top users | synonyms (1)

5
votes
1answer
55 views

JavaScript program to count lines of Java code

I've implemented a small program in JavaScript to count the number of lines of a string of java source code. This was done for one of the Code Kata exercise: ...
2
votes
1answer
36 views

Get K most frequent tokens from a token stream

This is an interview problem: Given a token stream, find the K most frequent tokens in real time (the order of these k tokens does not matter). My approach: Use a hash table (...
2
votes
1answer
66 views

Function to compare phone numbers

I got rejected in tech screen yesterday. I was asked to write a JavaScript function and send it over email. The question was(I have added the full question below). I have also added hiring manager's ...
6
votes
3answers
336 views

Finding the postion of a substring in a string

I am given two strings and return the position if in the larger string the smaller string is found. If not I am returning -1 for position. Any suggestions for improving my code. ...
6
votes
1answer
128 views

Are AVL trees equal?

I was inspired by this answer and decided to implement an AVL tree with the methods equals and hashCode as if I was asked to do ...
7
votes
1answer
69 views

Designing yet another coffee machine, Lombok style

After reading Designing a coffee machine, I decided to implement the same problem as an exercise to get to know Guava and Lombok. I used the problem statement from the given question: Design ...
-3
votes
1answer
73 views

Implemented Stack using array

I'm going to job interviews soon. How I can improve my coding style and write better code? ...
4
votes
0answers
50 views

Swap items of a linked list in pairs - revision 5

Here is the source of the question. Given a singly linked list, swap the list items in pairs (reconnect the pointers, not simply swap the values). For example: Before: A->B->C->D ...
2
votes
2answers
61 views

Hike in recession by a company based on criteria

I was going through design questions frequently being discussed in interviews and have found a problem which states: Consider a company which wants to process salary hikes of its employees ...
5
votes
4answers
224 views

Find the common element in two int arrays

I am preparing for a interview for a junior level c# position. I take two arrays and find the common int between both of them. Let me know if you have any feedback. ...
4
votes
3answers
198 views

Most common occurrence of an int in an array

I am prepping for a junior level interview in C#. I am hoping I can get some feedback on how to improve my code to print the most common occurrence of an int in an ...
1
vote
1answer
58 views

Swap items of a linked list in pairs - revision 4

Here is the source of the question. The solution on GitHub. Revision 1. Revision 2. Revision 3. @200_success' suggestions from revision 3: The iterator's ...
2
votes
1answer
31 views

Swap items of a linked list in pairs - revision 3

Here is the source of the question. Revision 1. Revision 2. When I started the second round of code review, I wanted to make sure that I had included all the possible input types. However, I ...
3
votes
1answer
62 views

Checking for uniqueness within a string

I saw this interview question in the book Cracking the Coding Interview: Implement an algorithm to determine if a string has all unique characters The authors solution uses bit-shifting for a ...
10
votes
4answers
821 views

Method to count all comments in single external C# file

I recently had an interview question: Write a method that counts all comments in a single external file. It was a timed question and I wanted to know if this is the best way to accomplish the ...
3
votes
1answer
65 views

Swap items of a linked list in pairs - revision 2

The first revision is available here and the code is available on GitHub. I modified the method reversePairs and added mSize to ...
10
votes
1answer
109 views

Concurrency interview

A little while back I had an interview where they posed a problem, in summary: Watch a certain directory, and process incoming JSON files These JSON files have various "Type" fields Every second ...
10
votes
1answer
105 views

House-coloring optimization challenge

I have an interview coming up in the next few weeks, and I'm choosing to be interviewed in Python. I began programming in Python (it was about four years ago), so the syntax is natural to me, but I ...
2
votes
1answer
132 views

Swap items of a linked list in pairs

Here is the source of the question: GitHub Given a singly linked list, swap the list items in pairs (reconnect the pointers, not simply swap the values). For example: Before: A->B->C->D ...
7
votes
2answers
130 views

Determine if string has all unique characters

I'm working my way through the exercises of the book Cracking the Coding Interview. I'd like to review my solution for the question: Implement an algorithm to determine of a string has all unique ...
10
votes
1answer
183 views

Robot toy simulator

I have already flunked the test with this code so don't feel bad for cheating any employer. I didn't get any feedback though just wondering what could have gone wrong. You don't need to get into the ...
5
votes
2answers
125 views

C++ 2D shape intersections - template reduction

I've created a short piece of code to determine whether or not various 2D shapes (circles/lines/rectangles) intersect. It was a job interview question, but now it's just about self-improvement. I'd ...
5
votes
4answers
264 views

Sufficient implementation of subset sum for 45 min interview

I am preparing for interviews, and have implemented a solution to this problem from Geeks for Geeks: Given a set of non-negative integers, and a value sum, determine if there is a subset of the ...
2
votes
1answer
78 views

Interview adjacency list graph problems in C++: proper graph implementation

I know this type of question has been asked before. However, my reason for asking it is gaining insight into what is expected in a 45 min interview when asked to implement graph algorithms. I have ...
11
votes
7answers
943 views

Scoring a Scrabble Word

I was asked before an interview to create a console application that will work out the score of a word for the board game scrabble. It worked fine but the feedback I received said: "there were no ...
7
votes
3answers
243 views

Calculating the area of a circle

This is one of tasks, which I had to do for the recruitment process at some company. Unfortunately they didn't like it so I've decided to share it here for discussion. CircleArea.h ...
2
votes
1answer
111 views

Find pairs in an integer array whose sum == 10

I'm practicing for technical interviews and I'm looking for ways to improve my answers/code. Please point out the flaws you see and how I can make this better. Task: Find pairs in an integer array ...
-2
votes
2answers
91 views

Comparing 2 ints without using comparative operators

I was looking for questions that might be asked in a technical interview and I found this one: Write a function that determines if two integers are equal without using any comparative operators. ...
-2
votes
1answer
133 views

Find the GCD for given array of elements [closed]

I had faced a interview question to find the gdc(greatest common divisor) for an integer array of element in optimised way : ...
5
votes
2answers
156 views

Return a rank for string of letters based on alphabetical permutations

So, first off, a little bit of unrelated information: I am preparing for a technical interview. I was reading this article, How to Prepare for (and Ace) the Technical Interview, by Rich Hein and I ...
11
votes
1answer
87 views

Top wiki pages as an app

I recently did an interview task. I was rejected because of bad code quality. There was two tasks. Here I will present the first, second will be posted in time. This project is avalible on GitHub ...
4
votes
4answers
151 views

Find Kth largest element in an array

I am preparing for interviews where my code would be judged based on optimizations, OOP concepts, code readability as well as my knowledge of JAVA and design patterns. What comments will you give in ...
3
votes
3answers
155 views

Reversing strings using recursion

I'm trying to solve exercises where I am required to use recursion. I wrote this: ...
3
votes
1answer
648 views

Find the kth largest element of an array

Find the kth largest element in an array of integers. You may assume that 1 <= k <=size(array) Any comments? Is there a more efficient solution? ...
3
votes
3answers
158 views

Number of right cyclic shifts to give the biggest number

I am preparing to coding interview and I met this task today: You are given 30-bit unsigned integer N. A right cyclic shift of N by K bits is the result of performing a right cyclic shift of N by one ...
3
votes
3answers
318 views

Letter combinations of phone dial pad number

In preparation for interviews, I have written a solution to this question: Given a sequence of numbers (34128) and an input map such as a dial pad on a phone (2->[a,b,c], 3->[d,e,f], ...
17
votes
6answers
2k views

Sales Tax Problem, rejected for not being up to their standards

I applied for a Junior .NET Developer Position recently, and I was asked to solve a problem (Sales Tax Program) and I was rejected for some reason. The question goes like this: Basic sales tax is ...
11
votes
2answers
162 views

Did not pass the interview about an RPN Calculator

I recently received a simple interview assignment as to implement an RPN calculator in Ruby. The program takes user input and quits when the user presses 'q'. I did it in under 30 minutes and was ...
34
votes
3answers
3k views

Sorting millions of integers

Last Friday I was hit with a sorting interview question that I never really had to deal with. Develop a your own sorting algorithm. It cannot use any other Classes for help. It needs ...
4
votes
2answers
353 views

Merging sorted arrays

I'd like to know if it's ok to write like this or there is a better, prettier way to do this. The merging itself is ok. I'm more interested in dealing with the situation when one of the arrays is ...
5
votes
1answer
154 views

Given a binary tree, compute the min depth of a leaf node

Here is the source of the question. They don't require a tree to be a BST, but my tree is. The algorithm would be the same for a simple binary tree. And there are two implementations: A recursive ...
6
votes
3answers
205 views

Finding clusters in a matrix

I got asked at an interview to write a program that, given a NxM matrix with zeros and ones, prints out the list of clusters of 1s. The clusters are defined as patches of 1s connected horizontally, ...
41
votes
10answers
4k views

Sales tax calculator, rejected for being not OOP

I applied for an Application Developer position. They require all their applicants to complete 1 of 3 programming assignments. I picked one for sales tax calculation. It was quite simple. ...
2
votes
2answers
237 views

Survivor programming challenge

I am working on a survivor problem: Complete Question Text: Take a second to imagine that you are in a room with 100 chairs arranged in a circle. These chairs are numbered sequentially from ...
15
votes
3answers
2k views

Finding anagrams - Empires strike back

Recently as part of a job interview I was given the following coding task: Attached is a gzipped text file of about 100,000 English words. Write a Python, C or C++ program that finds all the ...
4
votes
7answers
256 views

Printing a multiplication table

I was recently given a coding test by an employer. After the test, this was the employer's response: "I’d say that a lot of his solutions were pretty inefficient and took a very ‘brute force’ ...
14
votes
5answers
622 views

Given a sequence of positive integers A and an integer T, return true if a continuous sequence of A sums up to exactly T

Here is the source of the question, and my solution is below. Did I determine the worst case correctly? If you find any input where it doesn't work, please let me know. ...
2
votes
1answer
86 views

Highest pit - only climbing through the pit once

For a problem description, see other question. Imagine I would write this code at an interview. What would you say? Time complexity: \$O(n)\$ Space complexity: \$O(n)\$ Auxiliary space complexity: ...
2
votes
1answer
840 views

Find the max. difference between two array elements a[j] and a[i] such that j > i

The source of the problem is here. Given an array of integer elements, return the maximum difference of any pair of numbers such that the larger number of the pair occurs at a higher index ...
6
votes
2answers
385 views

Android App Interview (Minesweeper game)

I recently did an Android Minesweeper app for a pre-interview coding challenge before I could talk to any engineer and was rejected. This feedback was given but I'm not sure on some of it. ☺︎ Game ...