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.

834 questions
Filter by
Sorted by
Tagged with
84 views

### Find GCD of two numbers without using multiplication, division or modulus operators

If either a or b is 0 return the other number. If both even return gcd of a/2 and b/2. If either a or b is even divide it by 2 and return gcd of the pair. If a less than or equal to b, return the gcd ...
492 views

### Three sum using binary search

Given an array and a value, find all the triplets in the array whose sum is equal to the given value. For example, if the given array is {12, 3, 4, 1, 6, 9} and the ...
68 views

### Generate power sets given a set of elements in java

For an array of length n, the possible number of subsets is Math.pow(2, n). for each value between 0 and Math.pow(2, n), see the index at which the bit is set, and include the corresponding number in ...
2k views

### Check if the given string has duplicates

Description: Given a string find if it contains duplicate characters. The string contains only ASCII characters. Code: ...
1k views

### Three sum problem using HashMap in Java

Given an array and a value, find all the triplets in the array whose sum is equal to the given value. For example, if the given array is {12, 3, 4, 1, 6, 9} and the ...
976 views

### Reverse the digits of an Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Return 0 if the result overflows and does not fit in a 32 bit signed integer This is my approach: <...
2k views

### Find all triplets in array that add up to a given sum

Given an array and a value, find all the triplets in the array whose sum is equal to the given value. For example, if the given array is {12, 3, 4, 1, 6, 9} and the ...
530 views

### Find all pairs in an array that sum to a given number without using HashMap

Find all pairs in an array that sum to a given number without using HashMap. Duplicate pairs are not allowed. Input array cannot be modified. input: ...
236 views

### Code to call Space X API and display results

This is a technical test from a job interview. The feedback was that although it does as asked, the application structure wasn't great. As a beginner I'm not entirely sure what's wrong with it and ...
544 views

### Clockwise spiral traversal of 2D input matrix

I found this interview question online at Pramp: Given a 2D array (matrix) inputMatrix of integers, create a function spiralCopy that copies ...
88 views

### Rearranging numbers of an array like a wave

Given an array of integers, sort the array into a wave like array and return it, In other words, arrange the elements into a sequence such that a1 >= a2 <= a3 >= a4 <= a5..... Example ...
1k views

### LZW Decompression Library

I've been asked to write a decompressor library for an interview process. It's a LZW decompression library. I've got it working and tried it out. I'm looking for any feedback on structure, ...
138 views

### Pairs with Specific Difference python

Given an array arr of distinct integers and a nonnegative integer k, write a function findPairsWithGivenDifference that returns an array of all pairs ...
8k views

### Finding common elements in two arrays

I just had this question in an interview. I had to write some code to find all the common elements in two arrays. This is the code I wrote. I could only think of a 2-loop solution, but something ...
337 views

I'm working on an interview code sample in Javascript, which is not my first language. The task is simple enough: Given a webpage with a variety of images, allow the users to add comments. The code ...
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 ...
122 views

### Python: OOP design for event pricing updates

This was an interview question, I was supposed to refactor the EventPricingUpdate class to reduce the amount of nested ifs. Here are the basic rules: ...
822 views

### Given points on a 2D plane, find line that passes through the most points

Could someone give some feedbacks from perspective of oo design and coding style on the following codes: Question: Given n points on a 2D plane, find the Line with maximum number of points that lie ...
5k views

### Vertically print a list of strings to STDOUT into 3 columns with column lengths as balanced as possible

This was a interview question I struggled with, I am posting my solution hoping to look for more elegant/efficient solutions. Problem: Given a list of strings, print its element out to STDOUT one by ...
11k views

### Mini bank application

Today I went to an interview with the Cleartrip software company. For the first round programming, we need to build a mini bank application. In the question paper they clearly mentioned that no data ...
444 views

### Longest Arithmetic Progression Algorithm

Problem Statement: > Given a sorted array, find the length of the longest arithmetic progression in it. Examples: numbers = new int[]{1, 3, 4, 5, 7, 8, 9} The length is 5, and the ...
2k views

### Return the anti-diagonals

Give a N*N square matrix, return an array of its anti-diagonals. Look at the example for more details. Example: Input: ...
161 views

### Merging JSON and inserting into the DOM

I'm an aspiring junior dev. This is modified version of the code I wrote for a technical interview I did today (Didn't pass. Sad.). The problem was to fetch two json files, and display their data on a ...
2k views

### Stacks: Balanced Brackets Hacker Rank

Here is the general goal of this exercise: For each string, print whether or not the string of brackets is balanced on a new line. If the brackets are balanced, print YES; otherwise, print NO. ...
113 views

### Array's reverse vs simple arithmethic

I was asked to print numbers from 100 to 1 in a for loop with the index starting from 1. I came up with this solution: ...
1k views

### Compare two lists to see if one is a rotation of the other

Going through a list of common interview question, this was the next one. Any suggestions on performance and improvement? What would be a better implementation of this? Also correct me if I'm wrong, ...
603 views

### Calculating linux based octal file permission

I'm applying for a mid level devloper position. In order to progress to 2nd interview, you need to pass a technical test. One of the questions was to write a function to work out linux based octal ...
860 views

### Find The Duplicates in two arrays

Find The Duplicates Given two sorted arrays arr1 and arr2 of passport numbers, implement a function findDuplicates that returns an array of all passport numbers that are both in arr1 and arr2. Note ...
4k views

### Given a string of brackets, return the count of brackets that are properly matched

A string of brackets is considered correctly matched if every opening bracket in the string can be paired up with a later closing bracket, and vice versa. For instance, “(())()” is correctly matched, ...
82 views

### Phone call service providers cost checket

The question: You have many phone calling service providers. They each have a prices and special deals for many phone numbers. Design an algorithm and a data structure to support the function,...
68 views

### Failed job application test: program which alters 2d list based on commands

I recently was given this question for an interview application and am wondering where I went wrong. (The whole answer is contained in a skeleton which they gave me which I haven't included here so it'...
5k views

### Simple checkboxes with React

I was given the following exercise as part of a job interview process. I submitted my code and received the feedback that my solution is "close" but not "correct". My code executes just fine and ...
557 views

### Longest Valid Parentheses

This is the "Longest Valid Parentheses" problem from leetcode.com: Given a string containing just the characters "(" and ")", ...
128 views

### Pascal Triangle c# code space complexity

can you give me your impression of my implementation of Pascal triangle problem? I'm especially interested in space complexity evaluation thank you all! ...
2k views

### Flatten Dictionary Python challenge

I have a question about this coding challenge for "Flatten a Dictionary": Given a dictionary dict, write a function flattenDictionary that returns a flattened version of it . If you’re ...
3k views

### Merge k sorted array in python

I got asked this following interview for the following problem. Wondering if you have any thought and feedback for 3 solutions below: Merge k sorted linked lists and return it as one sorted list. ...
5k views

### Find and delete an item from a singly linked list in Python

Given a Singly Linked-List, implement a method to delete the node that contains the same data as the input data. Example: delete(1->2->3->4,3) ==> 1->2->4 ...
486 views

### Solving “Quadruple sum” problem using dynamic programming

I am trying to learn dynamic programming using hash table. I was given this the "Quadruple sum" problem from firecode.io as a challenge: Given a sorted array of integers and an integer target, find ...
731 views

### Find spiral 2D matrix (List of Lists) of ints in a clockwise spiral

I got this question during my interview with Microsoft. The question called 2D Snake. I'm wondering if my solution 1 passes the test, but if my solution 1 different from solution 2. Let's have ...
176 views

### Solving this Python implementation for Stock Gains

I wanted to ask for a code review for the following interview question: Problem: Max Gain Given an list of integers, write a method - max_gain - that returns the maximum gain. Maximum Gain is ...
2k views

### Find the intersect area of two overlapping rectangles

This is my solution to find the coordinates of 2 overlapped rectangles implemented in JavaScript. Each rectangle is represented by 2 points, each with 2 (x,y) coordinates. Can this code be improved?...
2k views

### Maximum Sum of Non-Adjacent Elements

Purpose I recently came across an interview question that stumped me for a while Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. I am looking for ...
193 views

### C++ Interview preparation questions - Find the maximum sum of subarray in array

I am currently prepping for C++ interview question, by answering some I found on the internet. I don't think my solution is the best, but on the other hand, I am not sure what else would be a better ...
1k views

### Reversing the words order of a string

A couple of weeks I had a coding interview and the problem to solve was very simple: reverse the words order of a string. What did I do wrong here? ...
524 views

### Detecting if two strings are anagrams

I am trying to write a function that detects if two strings are anagrams of one another; more specifically, I want the function to be linear in its time complexity ($O(n)$ where $n$ is the length ...
374 views

### Interview practice: Integer to Roman

Student here. I'm practicing for coding interviews right now. In that context, how would you recommend I improve my code for this practice problem? ...
471 views

### binary search tree Inorder successor to test candidate confidence

Problem statement Given the root node and a node in the binary search tree, find the inorder successor of the given node. Here is the example of binary search tree, Given the node with ...
1k views

### Ukkonen's algorithm for longest common substring search

I am working on a programming interview practice question in Python 3 (on codefights.com). The challenge is to return the length of the longest substring that appears in both of two input strings. The ...