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

learn more… | top users | synonyms (2)

1
vote
1answer
47 views

Pattern searching in 2d grid

This is an interview question which i am trying to solve. You are given a 2D array of characters and a character pattern. WAP to find if pattern is present in 2D array. Pattern can be in any way (all ...
5
votes
1answer
80 views

A roman to integer converter

For an interview question I made a roman to integer converter: ...
11
votes
1answer
110 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 ...
6
votes
1answer
102 views

Implement 3 stacks using a single array in C++

One of the questions that is presented in Chapter 3 for Cracking the Coding Interview is this: Describe how you could use a single array to implement 3 stacks I'...
2
votes
1answer
50 views

Total number of stops for an elevator to serve certain people

I have seen this question asked around a bit, such as this Code Review question in Java: Write an optimal program that would determine the total number of stops a elevator has taken to serve X ...
0
votes
2answers
74 views

Google Foobar Challenge: Spy Snippets in Python [closed]

I am getting all the answers correct. But still the solution is not accepted as only 4/5 tests cases are passed. I have not posted the whole problem statement but the problem is similar to this. I ...
10
votes
1answer
156 views

Implementing a string class in C++

I recently attended an interview for a C++ position in a very reputed bank. The interviewer started off by asking me to implement a string class but was only interested in constructor, copy-...
7
votes
5answers
1k views

Interview solutions to reverse a string and reverse a sentence

Recently in an interview I was asked to Write a method to reverse a string. I used StringBuilder but was asked not to use reverse method of builder but iterate ...
0
votes
0answers
61 views

Find the kth largest element in an array

Is this idomatic scala code? ...
5
votes
2answers
44 views

Parsing shorts from binary file and finding the closest and furthest points

A few months ago I got rejected at the technical interview for a position. The problem that they gave me is the following: From a binary file, parse two shorts, x and y and build a Point object with ...
7
votes
1answer
111 views

Make Simultaneous HTTP Requests That Resolve Into a Single Return

This week, in an ongoing job search, I was tasked with the following pre-screening question: Make two simultaneous http requests. Use the language and library of your choice. Make sure the results ...
0
votes
1answer
33 views

Convert NSInteger into NSString

This is my sample code to convert a integer into string. Is it very costly to do the multiple loops of [NSMutableString stringWithFormat:..]? I.e should I just use appendString and get the NSString ...
7
votes
2answers
144 views

Load and analyze a list of people from a file

I recently completed a programming task in Java for a job that was javascript heavy but the hiring company wanted some Java knowledge. I've been using Java since the turn of the year. Other than ...
4
votes
3answers
128 views

Reversing a linked list (Java)

Triggered by an interview question (I didn't answer during the interview) I wrote a Java program to reverse a linked list. I went with a loop-based approach instead of recursion. I would like to know ...
3
votes
2answers
91 views

'Broken Record' Coding Challenge

I was asked to complete a coding challenge for an interview. The challenge being to write a test function to check whether or not a string was a broken record. A <...
6
votes
4answers
992 views

Implement an algorithm to determine if a string has all unique characters

I'm working through Cracking the Coding Interview. The first challenge is to implement an algorithm to determine if a string has all unique characters. I've gone through several iterations, but here'...
1
vote
2answers
51 views

Pseudo Promise.all() polyfill

A few years back I interviewed with a company for a Javascript position. After a couple of warm-up challenges I was presented with this: Please write a function that calls back with ...
5
votes
2answers
65 views

Java controller to farm out concurrent tasks

I've recently given a coding interview on a Java concurrency task and unfortunately didn't get the job. The worst part is I've given my best but now I'm not even sure where went wrong. Can anyone ...
4
votes
1answer
170 views

SVG photo mosaic creator

I got this as part of some interview assignment. After some head scratching I think I have done quite well as the result can be seen here: After transformation(10x10 tile): More crisp picture ...
5
votes
3answers
277 views

Finding the duplicate with an array with 1,000,000 integers between 1 and 1,000,000

I recently had an interview and got to phase 2 which is a coding assessment. One of the questions was: Given an array with 1,000,000 integers between 1 and 1,000,000, one integer is in the array ...
12
votes
6answers
2k 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 ...
1
vote
4answers
148 views

Program to display array elements in the ascending order of number of factors each element has

Input: 1000 23 100 26 32 Output: 23 26 32 100 1000 Since 23 has '2' factors and 26 has '4' factors and 32 has '6' ...
6
votes
3answers
228 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
5answers
285 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
81 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 ...
5
votes
2answers
91 views

Rails controller to manage EC2 instances

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
46 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
65 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
114 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
60 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
963 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: ...
4
votes
3answers
165 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 ...
14
votes
1answer
378 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
120 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 ...
0
votes
1answer
152 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
122 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
165 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
831 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
70 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
75 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
64 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
148 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
128 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
38 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
59 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
138 views
0
votes
3answers
61 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
71 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
53 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 [...