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

learn more… | top users | synonyms (2)

0
votes
1answer
38 views

Flatten an array

I have got this interview question which has asked me to write a production level code which flattens the arbitrary nested array of arrays. Code ...
6
votes
4answers
226 views

A custom String Builder implementation

Two code files below : the actual logic & the test logic. Core Logic ...
10
votes
3answers
2k 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. ...
2
votes
2answers
73 views

Returning a filtered list of iPhones

I have just received feedback regarding a junior dev test that I submitted. It was unfortunately not great, and the recruiter could not articulate the issues, I tried to show that I was thinking about ...
4
votes
1answer
61 views

Rails Sample for interview

I did a small sample application for an Interview. Since I didn't got accepted I would like your opinion on how to improve it. The aux methods are private. I have a ...
1
vote
0answers
37 views

Improving time efficiency of finding maximum area rectangles in a histogram

Here's my solution but I am looking for ways to improve the time complexity of solution. Also this question is categorized as being solved by stack so I would like to know how to approach it using ...
-4
votes
1answer
52 views

Recursive solution for merging two sorted lists [closed]

I came up with a recursive solution for merging two sorted list in Python in interviewbit: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing ...
4
votes
1answer
102 views

Improving time complexity of finding the longest palindrome in Python

The Longest Palindromic Substring challenge from InterviewBit: Given a string S, find the longest palindromic substring in S. where a "substring" must be contiguous, and in case of ties the ...
3
votes
1answer
55 views

Create a generator that returns every permutation (unique arrangement) of positive integers up to n

I watched this video from The Unqualified Engineer on YouTube and tried out the challenge. The challenge (or interview question) is to build a generator that returns all the permutations of the ...
4
votes
3answers
923 views

Top 5 most common words in Python

I would like to hear feedbacks from an interviewer's perspective on how to improve the following code: ...
3
votes
3answers
151 views

Bitcoin trading system

Recently I did an exercise for a interview pre-screening, but was not selected. They did not give much detailed feedback apart from "the code was not up to what they wanted". It would be really ...
13
votes
1answer
362 views

Match Three game for a job interview using Cocos2d-x

The problem is that I had an interview for a gaming company and I had to write a prototype of a Match Three style game. The time line was 3 days. I made the code in about 2 days and sent it to them. ...
3
votes
3answers
98 views

Find majority element in an array given constant external space

Given constant external space (yes no HashMap), how would you improve the following code (code-wise or complexity-wise with stress on the latter) to find the ...
1
vote
1answer
73 views

Rearrange String such that similar characters are placed at least 'K' distance apart

So I was asked this in an interview, and I had to write this code on a white board. Sadly I couldn't complete the code :( . I've realized that writing code on white board is completely different ...
0
votes
3answers
97 views

Detecting if two given strings are isomorphic using Java data structures

So I have written the following code and it works for various same length isomorphic strings I have tried. However I am not sure what are some time complexity improvements and coding tweaks that could ...
2
votes
4answers
152 views

Reverse Polish Notation Evaluation in Java

I would like to hear feedback about my code both in term of improving efficiency if possible or using other data structures. Also go ahead and let me know about code styles/patterns. ...
6
votes
4answers
824 views

Detecting if two strings are anagrams using TreeMap

I decided to use Java TreeMap because it seems like a great data structure to fit this problem. However, I am not sure if there could be much simpler methods using ...
3
votes
1answer
60 views

Faster palindrome checker in Java

I wonder if there could be a faster palindrome checker in Java. The best one I have is O(n/2) which is O(n) eventually: ...
3
votes
2answers
67 views

Duplicates in array elements and sorting

I've been given this little test exercise for an interview as php developer, and I'd like to hear from you if my solution is good (enough) or if the problem could have been solved in a better way. ...
3
votes
2answers
59 views

Merge and sorting arrays of String and int in more efficient methods

Are there better methods for merge and sorting arrays of int and String in more efficient methods both time-complexity wise and ...
3
votes
2answers
123 views

C++ Graph Class Implementation (adjacency list)

I've got a barebones C++ graph class implemented as an adjacency list. The graph consists of a vector of vertices. Each vertex has a vector of outgoing edges that store the destination vertex id. ...
5
votes
1answer
108 views

Caches implementation in C++

I had a test task for internship where the main part was in implementing fixed size caches with different displacement policies (LRU/LFU/FIFO). I did that task, but was refused afterwards. Now I am ...
1
vote
0answers
33 views

Checking whether a directed graph contains a cycle

I create a myGraph class as shown below. Then I created an instance of the graph by giving the adjacency list as a NSDictionary and then call the isGraphCycleFree method. Will this answer look good ...
3
votes
1answer
56 views

Efficient File Searching

During an interview I was asked to consider the following: You are trying to find an instance of an error code within a number of log files within a directory. The goal is to count the number of ...
4
votes
2answers
125 views
0
votes
3answers
59 views

Counting occupants in each HouseHold provided large file of comma seperated personnel records

I was given the below Exercise as part of a coding Exercise to do at home for a technical interview, and I did not get through past this round. I would like to get some input on what i could have ...
4
votes
1answer
66 views

Sort a stack in descending order

Maintain current element as the top element in the input stack. Pop all the elements on the ordered stack which are greater than the current element and push them in to the input stack and maintain a ...
2
votes
1answer
47 views

Find the contiguous subarray within an array (containing at least one number) which has the largest sum

Interview Q: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example: Given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [...
5
votes
3answers
165 views

Interview coding test: Searcher

I did a task for an interview and the solution was not accepted. The task was to implement the class search function by name. The number of classes in the input data from 0 to 100000. Class names are ...
34
votes
7answers
12k views

Interview coding test: Fizz Buzz

I was recently given a coding test to complete for a potential client. It was a FizzBuzz-type of thing with a two-hour time limit. I had a request to write basic FizzBuzz, then add a special case, ...
-1
votes
1answer
58 views

Determining whether a string can be rearranged into a palindrome

For a string, count the number of occurences of each character. If at most one character has odd count then the string can be a palindrome else it's not. ...
4
votes
1answer
106 views

Finding number of times each string in an Array of strings occurs in a large stream of characters (i.e large string)

Interview problem: Given a stream of characters (e.g. acacabcatghhellomvnsdb) and a list of words (e.g. ["aca","cat","hello","world"] ) find and display count of each and every word once the ...
1
vote
2answers
51 views

Calculate Kth Row of Pascal's Triangle

Purpose Implement a solution that returns the values in the Nth row of Pascal's Triangle where N >= 0. Math First three rows ...
3
votes
3answers
193 views

Football game using factory and command patterns

I'm really confused about the interview I did with a firm. They told my code was not expert, but almost intermediate level java. Requirements Football Scoring Dashboard Develop an application that ...
6
votes
3answers
428 views

Given an unordered list of numbers, find all pairs that add up to x

I am coding an interview question from Yahoo Software Engineer Intern Interview. Given an unordered list of numbers, find all pairs that add up to x. I have a working solution in Java: ...
2
votes
3answers
87 views

Minimum element in a sorted rotated array

A sorted array [0,1,2,3,4,5] when rotated n times (3 times in this case) becomes [3,4,5,0,1,2], meaning elements in the front move to the end. The code below finds the minimum element in this array, ...
15
votes
2answers
1k views

Python backend interview: task management system for workers

I've recently applied to a backend position and I was asked to complete a take-home interview question. I thought the question was rather simple and I completed in about an hour although I was told it ...
3
votes
2answers
124 views

Decimal number to binary number conversion in JavaScript

I made this decimal to binary conversion as an exercise for myself and because it is obviously often asked during job interviews / tests. Any hints concerning possible improvements welcomed. <...
2
votes
2answers
155 views

JavaScript function to convert decimal number to binary

I was recently asked this in an interview for a front-end position and I came up with something like this which seems to work but is clunky. (Number.toString() was ...
2
votes
2answers
39 views

Choose a color with probability proportionate to its weight in a group of colors

Input: An array of colors with weights. e.g [['red', 10], ['blue', 20], ['green', 30]] Output: A random color from the array, based on it's proportion to the other ...
2
votes
3answers
137 views

Adding minutes to a time value in Ruby

I recently submitted a code-challenge for an interview according to the following guidelines: About Write a function or method that accepts two mandatory arguments and returns a result. ...
4
votes
1answer
54 views

Construct binary tree from inorder and postorder traversal

The problem is taken from here. The tree is guaranteed not to have duplicate elements. My questions is, instead of creating new arrays leftInOrder, ...
4
votes
1answer
51 views

Project Euler - Largest Product In A Grid

My code solves Project Euler problem #011: What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid? I looked over one ...
5
votes
2answers
157 views

Registering and looking up aliases

I've taken a coding challenge as part of a job interview and the recruiting process. Sadly I didn't get through it and couldn't secure the job. I am wondering if anyone can help me out here and show ...
10
votes
2answers
895 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. ...
5
votes
2answers
60 views

Making the same amount from different combinations of coins (top-down approach)

I was reading a typical interview question found here. Given an amount and a list of denominations, count the number of possible ...
1
vote
2answers
192 views

Rotate matrix 90 degrees clockwise

Please suggest improvements and a possible better way of doing it in place. ...
-2
votes
1answer
58 views

Finding Closest Sibling in a BST efficiently

Trying to print the closest sibling in a BST. How can I improve on this algorithm in terms of space/time efficiency? Please point out any potential bugs too! I'd appreciate that. ...
3
votes
1answer
44 views

Sum to zero of all triples in a list - n^2 running time

As part of an interview, I had to submit a code sample to solve the classical "triples sum to 0" problem. The reviewer said the algorithm needed to be in n2 time, and I was later informed that the ...
1
vote
2answers
63 views

Check if the undirected graph is cyclic

Here is my approach. Do DFS and check in stack whether the new node is already in the Stack or not. ...