Questions tagged [interview-questions]

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

Filter by
Sorted by
Tagged with
3
votes
1answer
80 views

Map Character to Characters Most Frequently Found With it (in list of strings)

For an interview, I was tasked with writing a program that consumes a list of strings, and produces a mapping between every character in the list, and the characters found most frequently with it (let'...
1
vote
2answers
255 views

String Compression

Implement a method to perform basic string compression using the counts of repeated characters. For example, the string "aabcccccaaa" would become "a2b1c5a3". If the "compressed" string ...
1
vote
0answers
4k views

Find the shortest path between two points in a 2D matrix with obstacles

I need to find shortest path between two points in a grid given an obstacles.. Given a 2 dimensional matrix where some of the elements are filled with 1 and rest of the elements are filled. Here ...
14
votes
4answers
874 views

String Encoder with lower-case output

Question: Take an input string and output the "encoded" string by using the following rules: ...
1
vote
2answers
134 views

HashMap implementation, is this good enough for interviews?

After understanding HashMaps, I decided to implement my own using 3 classes HashMap, LinkedList, and Node. I knew how to implement LinkedList from before. Can you please give me feedback on this. ...
3
votes
1answer
95 views

Find contiguous integers with a given sum

Introduction This question was asked in a technical interview, I am looking for some feedback on my solution. Given a list of integers and a number K, return which contiguous elements of the list ...
2
votes
1answer
56 views

Leetcode #826. Most Profit Assigning Work solution in Java (Sort + Binary Search)

Problem Statement: We have jobs: difficulty[i] is the difficulty of the ith job, and profit[i] is the profit of the ith job....
1
vote
1answer
54 views

Check if list contains a pair which adds up to a given sum

Kindly review this scala code for given problem and suggest improvements. Problem - Given an array of integers and a target sum, check if array contains a pair which adds up to sum. Example - <...
1
vote
0answers
53 views

Design a system for renting digital movies/books

During an interview I was asked to do an OO design for a digital renting system for books/movies. This is the design that I came up with. My assumptions: When the customer has downloaded a list of ...
1
vote
2answers
148 views

Balanced parenthesis, with backslash escaping

Given a Balanced Parenthesis problem. "Balanced Parenthesis Create a program that checks if in a given string expression all the parenthesis are balanced. For Example: (test) - valid ...
-1
votes
2answers
65 views

Given an integer number, invert its bits. You cannot use the ~ operator

Here is my code: ...
3
votes
2answers
126 views

Simple recursive transformation solution in Python

This simple Python code I wrote for a problem asked during an interview. The problem statement is: Given a tuple (a, b), transform this into (c, d) by applying any of the two below operations ...
2
votes
2answers
142 views

Top K frequent elements

I am working on an interview question where I need to return the k most frequent elements given a non-empty array of integers. Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Here is my code: <...
2
votes
1answer
202 views

Leetcode #146. LRUCache solution in Java (Doubly Linked List + HashMap)

Problem Statement Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be ...
1
vote
1answer
53 views

Find the combination of matches which are closest to each other

Problem - Given three sorted arrays find combinations which are closest to each other. example - ...
1
vote
1answer
194 views

Find maximum in sorted and rotated array

This is an interview question. A sorted rotated array is a sorted array which was rotated 0 or more times. For example: [1,2,3] -> [2,3,1] ...
0
votes
2answers
153 views

Design a system for creating a coffeeshop menu

During an interview I was asked to design the menu for a coffee shop employee so that the employee would go and add different items to the menu. This is the design that I came up with. I just want ...
3
votes
1answer
66 views

Mark positions attacked by a queen on a chess board

Problem - Given a chess board and the position of only one queen piece in it, mark all the position where the queen can move with X. Kindly review this Scala code and suggest improvements. ...
1
vote
2answers
169 views

Whiteboarding - Multiply all values in array except at the index for each

Consider this interview question: You have an array of integers, and for each index you want to find the product of every integer except the integer at that index. Write a method ...
1
vote
1answer
309 views

Converting employee survey data from CSV to JSON

This Java code project was submitted for a job opportunity but was marked down for showing "bad habits that could be difficult to unlearn" but I am mystified by what this means. Any takers please. How ...
1
vote
3answers
94 views

Determine a list contains two elements with a given sum

On interview I was asked to write method with following contract: boolean checkList(List<Long> list, long sum){...} for example it has to return true for ...
1
vote
1answer
1k views

Print odd and even numbers using two threads in Java

I was asked below question in an interview where I need to print out even and odd numbers using two threads so I came up with below code one without synchronization and other with synchronization. <...
2
votes
3answers
138 views

Exercise to refactor a class with various credit limit rules

I recently did a programming exercise for a company which I didn't pass. I didn't get any good feedback from my test so I wanted some advice/opinions for what I did wrong and what I could have done ...
1
vote
2answers
1k views

Check if a string is a valid english word, and convert to a valid english word

This is an interview question. For the purpose of the question, a valid English word is a string that begins with an uppercase English letter, and the rest of the string contains only lowercase ...
3
votes
3answers
474 views

Binomial coefficient in Java

Find nCr for given n and r. Input: First line contains no of test cases T, for every test case 2 integers as inputs (n,r). Output: Compute and print the value in separate line. ...
2
votes
1answer
168 views

Pramp: Sales path

the question is taken from Pramp(really cool site!) there is a more straight forward solution. using recursion. but I thought trying it using BFS. please review only the code of GetCheapestCost ...
1
vote
1answer
120 views

Smallest number in BST which is greater than or equal to N

Given a Binary Search Tree and a number N, the task is to find the smallest number in the binary search tree that is greater than or equal to N. Print the value of the element if it exists ...
1
vote
0answers
462 views

Electricity billing system for home in OOP

I recently appeared for interview for code-pairing round and I was asked following question: Electricity Billing System for home. The corresponding power usage of home appliances (Fan, AC, Fridge, ...
4
votes
1answer
187 views

Find largest smaller key in Binary Search Tree

Given a root of a Binary Search Tree (BST) and a number num, implement an efficient function findLargestSmallerKey that finds the largest key in the tree that is smaller than num. If such a number ...
3
votes
4answers
2k views

Find longest Palindrome substring

I am preparing for technical interview and I found this question on geeksforgeeks, but I did not understand their solution. So, I have written my own solution. I want to optimize this code. ...
4
votes
1answer
1k views

Maximum depth or height of a Binary tree

The Following function is supposed to calculate the maximum depth or height of a Binary tree the number of nodes along the longest path from the root node down to the farthest leaf node. ...
5
votes
5answers
448 views

Average of two hex colour values

I have submitted the following bit of script as the answer to one of the tasks I was set by a recruiter. My submission has already been made and cannot be altered. However, I am keen to ask how you ...
2
votes
0answers
108 views

Interview: Appointment reservations

I have received this question during an interview I did earlier, but I found that my solution might not be correct. And I would like to know whatever there is a better way to solve this. Question: ...
9
votes
2answers
253 views

Area calculator for shapes as an OOP interview test

A while ago a tricky C++ interview question came across to me, and ever since I could not tell what I did wrong. Create a base class named “Shape” with a method to return the area of the shape. ...
5
votes
1answer
15k views

Count duplicates in a JavaScript array

This is actually a hackerrank interview question I have already solved but I need guidance on how to optimize it for the Time Space Given an array of integers, your task is to count the number of ...
3
votes
1answer
96 views

Monoidal tree interview in Haskell

I was working on the following interview question: Given an array of integers, return a new array such that each element at index i of the new array is the ...
1
vote
1answer
89 views

Rearrange an array in place such that the first and last halves are interleaved

Given an array of n elements in the following format { a1, a2, a3, a4, ….., an/2, b1, b2, b3, b4, …., bn/2 }. The task is shuffle the array to {a1, b1, a2, b2, a3, b3, ……, an/2, bn/2 } without ...
4
votes
2answers
232 views

Calculating travel statistics based on CSV data

I took a code test for acme transport company and was rejected. That's ok. I'm still learning how to code. I didn't get much feedback so that's a bit frustrating. Can anyone here provide tips on how ...
4
votes
1answer
1k views

A tax calculator application to calculate tax and print final receipt

Although this question has been asked a lot of times, I was hoping for a feedback on my approach. Tax Calculator Basic sales tax is applicable at a rate of 10% on all goods, except books, food, ...
5
votes
1answer
117 views

Call center escalation excercise, using Chain of Responsibility pattern

This is a coding interview I found online, to be solved within 30 minutes: Design an OOP concept for an application where employee can dispatch their incoming phone call according to their ...
3
votes
1answer
330 views

Merge sort Java implementation for an interview

I just learned Merge sort, and I really like this Merge sort implementation since it is very logical and very easy to follow. If I was asked in an interview to implement merge sort, will this ...
4
votes
1answer
101 views

ZigZag tree travesal

The question is taken for a coding interview I had, it is also in geeks for geeks, https://www.geeksforgeeks.org/zigzag-tree-traversal/ you are given a binary tree and you need to print it in a ...
0
votes
1answer
59 views

Nodejs Interview - API calls and exchange rate

I did an initial technical phone screening with this company which went ok, they then sent me a programming exercise to complete and send back to them. The goal of the exercise: -take input as a ...
2
votes
3answers
110 views

Three Numbers in Java

Given three positive numbers A, B, and C. Find the number of positive integers less than D that are divisible by either of A, B or C. Input format The 1st argument given is an Integer A. ...
1
vote
2answers
132 views

Subset Sums in Java

Given an array of integers, print sums of all subsets in it. Output should be printed in increasing order of sums. Input : arr[] = {2, 3} Output: 0 2 3 5 Input : ...
1
vote
3answers
1k views

Sort all even numbers in ascending order and then sort all odd numbers in Descending order Java

Given an array of integers (both odd and even), the task is to sort them in such a way that the first part of the array contains odd numbers sorted in descending order, rest portion contains even ...
2
votes
2answers
115 views

Scroll text across a fixed width

In an interview, I was asked to write code to produce this output: T TE TES TEST EST ST T The code I wrote was: ...
2
votes
1answer
136 views

Interview Take Home Challenge: Chat server

Recent take-home challenge I was assigned from a recruiter prior to technical interviews with the team. The team wanted it written in GOlang (I had no experience in the language) but told the ...
5
votes
1answer
78 views

News reading application version 2

following the answer I got from t3chb0t last time News-reading application using the Observer pattern and also following the example here https://msdn.microsoft.com/en-us/library/dd990377(v=vs.110)....
7
votes
2answers
500 views

Iterator for BFS binary tree traversal

I implemented an iterator pattern for C# using IEnumerator and IEnumerable. The goal of the implementation is to traverse a ...