We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [interview-questions]

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

Filter by
Sorted by
Tagged with
14
votes
8answers
7k views

Find the first non-repeating character in a string: (“DEFD” → E)

I recently had an interview and got to phase 2 which is a coding assessment. One of the questions was: Find the first non-repeating character in a string: ("DEFD" --> E) I didn't pass the coding ...
14
votes
8answers
8k 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 ...
14
votes
6answers
18k 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 ...
14
votes
4answers
896 views

String Encoder with lower-case output

Question: Take an input string and output the "encoded" string by using the following rules: ...
14
votes
3answers
1k views

Equation Evaluator

I am currently applying to many Software Engineer positions, and have been asked to complete several coding challenges. The most recent was an equation evaluator, written in C++, that was supposed to ...
14
votes
2answers
804 views

Solve a set of “restricted” linear equations efficiently

I was recently asked to solve the following challenge (in C++) as part of the interview process. However, I haven't heard from them at all afterwards, and based on past experiences of unsuccessful ...
14
votes
1answer
9k 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 ...
13
votes
7answers
4k 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 ...
13
votes
6answers
7k views

Detect the missing number in a randomly-sorted array

I was reviewing for an interview and encountered the following question (and I'm paraphrasing): Suppose you're given a shuffled array of numbers containing all of the numbers between a min and a ...
13
votes
5answers
9k 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 ...
13
votes
2answers
2k views

Count the occurrence of each unique word in the file

I've been doing a task for an interview that I will have soon. The requirement is to code the following problem in C#. Write a program (and prove that it works) that: Given a text file, count the ...
13
votes
3answers
14k views

Get all combinations of selecting k elements from an n-sized array

Was asked this today in an interview. Didn't see it before, and spent quite a lot of time getting it to work (tricky with all the recursion). The goal was to find all possible combinations of ...
13
votes
3answers
14k views

Generate nth prime number in Python

Today I had an interview, where I was asked to solve this problem: Generate nth prime number. Given a signature below, write python logic to generate the nth prime number: ...
13
votes
2answers
2k 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 minimum ...
13
votes
1answer
988 views

Interview coding challenge for iOS Part 2 - the application in Objective-C and Swift

I recently interviewed with a company that needed a C/C++ programmer to work on the iOS side of the products. The job description indicated they needed someone with 4 years of Objective-C and iOS ...
12
votes
10answers
6k views

Tests for palindromes in C and C++

A question I've been asked on interactive phone screens is to code a test to determine whether a string is a palindrome or not. I am providing two examples here: one in C and one in C++. They both ...
12
votes
3answers
12k views

Counting permutations without repetitions for a number or a string

Can I make the following code faster with minor modifications? It times out on CodeWars website. ...
12
votes
5answers
878 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 libraries ...
12
votes
3answers
16k 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, ...
12
votes
7answers
27k views

Given an array of integers, return all pairs that add up to 100

I was recently given this programming challenge on an interview, and I decided to use javascript to solve it. I did, but I'm not happy with my implementation. I can't help thinking there must be a ...
12
votes
4answers
10k views

Palindrome-testing Java program for an interview

In an interview I was asked to write a function that would take an input word and return true if the word is a palindrome. At first I used an approach using ...
12
votes
3answers
5k views

Building car factory with custom features per car

I was once asked in an interview to build a factory that makes cars. All cars has common features like price, rating and color and they have some features like fuel injection which can on specific car ...
12
votes
2answers
827 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 ...
12
votes
2answers
6k views

LRU cache implementation

I have implemented an LRU cache, the question is taken from: leetcode: 146. LRU Cache Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following ...
12
votes
3answers
734 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 ...
12
votes
1answer
838 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 with ...
12
votes
1answer
4k 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 ...
12
votes
1answer
441 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 ...
11
votes
5answers
18k views

Checking if a number is power of 2 or not

This is my solution in Java and I need your opinion: ...
11
votes
10answers
27k 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 basic ...
11
votes
4answers
2k 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 task....
11
votes
3answers
546 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? ...
11
votes
3answers
19k 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: ...
11
votes
4answers
2k 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 number of times, find the index of its minimal element efficiently. If multiple such minimal elements ...
11
votes
5answers
16k 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 ...
11
votes
3answers
1k 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. ...
11
votes
2answers
948 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 ...
11
votes
5answers
5k views

Maximum product of 3 integers in an int array

I want to find the maximum product that can be obtained from any 3 integers in an integer array. The optimal solution has time complexity of \$O(n)\$ and space complexity of \$O(1)\$. I managed to ...
11
votes
4answers
28k 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 ...
11
votes
2answers
1k views

Stack having push, pop and return min in O(1)

I am using a class which is taking care of minimum value so far. Please let me know of any improvements or suggestions. ...
11
votes
4answers
15k 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 + ...
11
votes
3answers
893 views

Coding exercise to simulate animal population

(This is all available in a github repo if that's easier: https://github.com/paulnicholsen27/SpeciesSimulator) I am submitting this as a code sample for a possible job, so I'm just looking for any ...
11
votes
2answers
13k 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 ...
11
votes
2answers
25k 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 ...
11
votes
2answers
7k 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 ...
11
votes
1answer
146 views

Wandering water ways

An entry for the August 2016 Community Challenge I slightly modified the input and output to suit the snippet tool, and also because I really like the mapped output with the basins. I have been ...
11
votes
1answer
129 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 ...
10
votes
6answers
14k 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. <...
10
votes
7answers
2k views

Versatile string validation

I passed a technical test the other day, one part included a cheap string validation and I am wondering this can be further improved to be more versatile to requirement changes. The requirements were ...
10
votes
4answers
14k views

Counting occurrences of each word in a sentence

I have been doing this test task for C# Developer role at UBS.London recently and have been rejected. No reason stated yet. Was wondering if you can take a look and provide feedback on what I can do ...