Questions tagged [interview-questions]

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

Filter by
Sorted by
Tagged with
6
votes
2answers
2k views

Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all ...
1
vote
1answer
3k views

Remove Nth Node From End of List [closed]

Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the ...
2
votes
3answers
5k views

string to integer (implement atoi)

Implement atoi to convert a string to an integer. Requirements for atoi: The function first discards as many whitespace characters as necessary until the first non-whitespace character is ...
1
vote
1answer
3k views

remove all nodes with same value in a linked list

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, ...
5
votes
3answers
1k views

Given a number represented as an array of digits, plus one to the number

Given a number represented as an array of digits, plus one to the number. ...
4
votes
3answers
3k views

Length of last word

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Note: A word is ...
3
votes
2answers
2k views

remove duplicates in a sorted array if duplicates are allowed at most twice

Given a sorted array, remove the duplicates in place such that each element appear at most twice and return the new length. Do not allocate extra space for another array, you must do this in place ...
1
vote
2answers
246 views

Calculate difference of two ranges given

Write a method to compute the difference between two ranges. A range is defined by an integer low and an integer high. A - B (A “minus” B) is “everything in A that is not in B”. This is an interview ...
6
votes
3answers
2k views

interview question, friends, movies and likes

I was recently asked to implement an interface for a job interview. the class has methods to add customers and movies, the customers can watch or like movies and add friends. there are methods to get ...
3
votes
2answers
11k views

Run Length Encoding

Given an input string, write a function that returns the Run Length Encoded string for the input string. For example, if the input string is “wwwwaaadexxxxxx”, then the function should return ...
17
votes
7answers
135k 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 ...
8
votes
4answers
3k 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 ...
4
votes
1answer
379 views

Swedish Tax Calculator

I'm submitting this code in a couple of days as part of an an interview process. The company knows that I don't have any formal experience with Java. I'm hoping they are testing my ability to learn ...
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 ...
1
vote
1answer
1k views

Given a sequence of words, print all anagrams together

Given an array of words, print all anagrams together. For example, if the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then output may be “cat tac act dog god”. My idea is to sort ...
9
votes
5answers
13k 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 ...
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 + ...
2
votes
1answer
2k views

Lexicographic rank of a string

Given a string, find its rank among all its permutations sorted lexicographically. For example, rank of “abc” is 1, rank of “acb” is 2, and rank of “cba” is 6. Assuming there is no duplicated ...
8
votes
1answer
932 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 ...
12
votes
3answers
756 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 ...
4
votes
1answer
2k views

The number of connected component

Compute the number of connected component in a matrix, saying M. Given two items with coordinates [x1, y1] and [x2, y2] in M, if M(x1, y1) == -1 and M(x2, y2) == -1 and |x1-x2| + |y1-y2| ...
8
votes
3answers
7k 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
3k views

Pascal's triangle for an interview in PHP

I saw that one of the interview questions could be building a pascal triangle. Is there anything wrong with this particular solution I came up with? ...
11
votes
3answers
548 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? ...
2
votes
2answers
504 views

Optimization in overcoming TLE in interviewStreet problem

I have been trying to get the problem Quadrant Queries correct for a while now. Although my approach is an optimal one, I am getting a TLE on 3 test cases. Please help me optimize my approach so that ...
4
votes
3answers
2k views

Is this code too messy to send to an employer as a code sample?

A prospective employer asked me for a code sample, but unfortunately this is the best project I've done, most of my other programs were very short (~100 lines). Should I send this in/try to refactor ...
9
votes
5answers
51k 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 ...
0
votes
1answer
567 views

C/C++ code to do customized string comparing

It's an interview question, I was asked to compare 2 strings, and the number in the string are evaluated to integers when comparing. I can use C/C++ and can not use stl or stdlib. Some test cases ...
7
votes
3answers
17k views

Implementation of hash map

I was asked to implement a hash map in this phone interview (screen-share), so time was limited and this is what I came up with. I'd appreciate if someone can take a minute to critique/review it and ...
6
votes
5answers
4k 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 one....
3
votes
1answer
10k views

Convert number to words (web application)

I'm looking for a new job, and a company who had a role I was going for asked me to do a programming exercise. It consisted of making a web application of two or more pages that took a person's name ...
8
votes
3answers
6k views

Approximate String Matching Interview Question

I was working on the challenge Save Humanity from Interviewstreet for a while then gave up, solved a few other challenges, and have come back to it again. The code below generates the correct ...
4
votes
2answers
65k views

Deleting a node from a binary search tree

I have read about it at a few places and tried to write my own version. I would like to get it reviewed. ...
1
vote
3answers
6k views

Implement a function to check if a tree is balanced

Yet another interview question: Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ in ...
3
votes
3answers
7k views

Describe how you could use a single array to implement three stacks

I'm preparing for an interview so I'm trying to solve some problems to stretch my mind. Here is one: Describe how you could use a single array to implement three stacks. And here is my ...
22
votes
5answers
4k 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 ...
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. <...
16
votes
4answers
76k views

FizzBuzz implementation

The common FizzBuzz implementation I saw is using a check for % 15 for printing "FizzBuzz" Would you let me know if there is anything wrong / better with this approach? ...
3
votes
1answer
2k views

Java: Find the smallest integer not in the list - Memory Efficiency

This is a fairly popular interview question that I conceptually understand but have never really attempted to implement. In other similar implementations of this in Java I have seen they typically ...
8
votes
3answers
1k views

Reorder a list of courses, given their prerequisites

I recently graduated from college and applied for a position with a company. I was sent a coding exercise as part of the process. After completing the exercise and submitting it I was told that the ...
5
votes
4answers
3k views

Anagram Checker

Two words are anagrams of each other if they contain the same letters, such as "pots == stop". The easiest way to check is to sort both words, then compare. But that's an \$O(n*log(n))\$ solution and ...
3
votes
3answers
2k views

Possible combinations of bills that sum to the given amount

Question: You are given an array that represents bills in certain currency (for example 1, 2, 5, 10) and an amount, for example ...
5
votes
2answers
8k views

Simplified regular expression engine

Task: On an alphabet set [a-z], a simplified regular expression is much simpler than the normal regular expression. It has only two meta characters: '.' and '*'. '.' -- exact ...
15
votes
3answers
802 views

Sample game code for applying to a development firm

I am contemplating working with a development firm, and had asked for this piece of sample code. Could you please take a look and let me know if this is a quality piece of work, or if it needs ...
9
votes
3answers
40k views

Converting int value to String without using toString and parseInt method

I am studying about the converting int to string and string to int without using toString and parseInt method. I already made ...
5
votes
4answers
908 views

I have a home test for job interview

Nothing too special here, just a bunch of stuff. Please tell me if you would've done something different. ...
6
votes
2answers
4k views

Ways to improve my coding test FizzBuzz solution for a TDD role?

I had an interview recently where I was asked to produce the traditional FizzBuzz solution: Output a list of numbers from 1 to 100. For all multiples of 3 and 5, the number is replaced with ...
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. ...
10
votes
2answers
3k views

Fizz Buzz interview question code

Reading Jeff Atwood's "Why Can't Programmers.. Program?" led me to think that almost all of the solutions would not be something I would want in my own code-base. The Fizz Buzz program specification ...
2
votes
3answers
450 views

What is the security issue in this code?

I was asked how this code has a security risk. Does anyone have any ideas what it is? I am new on the security topic and don't know what to look for. ...