Questions tagged [interview-questions]

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

Filter by
Sorted by
Tagged with
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. ...
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 ...
1
vote
3answers
2k 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
1answer
215 views

Reverse a linked list

I was given 15 minutes to write the code to reverse a singly-linked list. What do you think of the code style here? ...
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 ...
1
vote
2answers
134 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 : ...
2
votes
2answers
116 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: ...
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 ...
6
votes
2answers
193 views

Find char which appears maximal number of times

I had 15 minutes to code the following question: Given a file name return the char which appears maximal number of times. please do not take into account the unit test. Please look at the final ...
5
votes
2answers
882 views

Remove the first value for a doubly linked list

You need to remove the first element which contains a given value from a doubly linked list. I created two solutions since I find the edge case of removing the first element to be problematic. So I ...
3
votes
3answers
424 views

Merge intervals

Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. GitHub ...
5
votes
5answers
1k views

Sort an array of 0s, 1s and 2s in Java

Write a program to sort an array of 0's,1's and 2's in ascending order. Input: The first line contains an integer 'T' denoting the total number of test cases. In each test cases, First ...
2
votes
3answers
836 views

Given a sorted array nums, remove the duplicates in-place

I wrote an algorithm to solve this challenge but would love some feedback on its efficiency and, if you were an interviewer, what your opinion would be on my solution. I believe my time complexity is \...
5
votes
3answers
1k views

Are strings anagram

This is a question from the book "Cracking the Coding Interview". Write a method to decide if two strings are anagrams or not I think interviewer will not be convinced with this solution because ...
2
votes
6answers
468 views

Alone in a Couple implementation in Java

In a party everyone is in couple except one. People who are in couple have same numbers. Find out the person who is not in couple. Input: The first line contains an integer \$T\$ denoting ...
30
votes
3answers
38k views

Overlapping rectangles

I received the following question in a technical interview today (for a devops/SRE position): Write a function which returns true if the two rectangles passed to it as arguments would overlap if ...
4
votes
2answers
1k views

Remove duplicate characters in a string

This is a question from the book "Cracking the Coding Interview". Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer NOTE: One ...
5
votes
4answers
324 views

In-place reverse of C-style string

This is a question from the book "Cracking the Coding Interview". Write code to reverse a C-Style String (C-String means that “abcd” is represented as five characters, including the null ...
3
votes
1answer
2k views

Solving maze problem with backtracking solution using stack

I solved the maze backtracking question using a stack however could not find any other solution like that anywhere (to validate my solution is actually a valid one). The problem statement is as ...
2
votes
1answer
374 views

Group Anagrams Together approach in Java

Given an array of words, print the count of all anagrams together in sorted order (increasing order of counts). For example, if the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then grouped ...
9
votes
5answers
50k 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 ...
2
votes
1answer
65 views

Top 2 Frequent Elements in JavaScript

I got the original problem from Leetcode for top k frequent elements, But I decide to simplify the problem just top 2 elements to make it simpler to solve. ...
0
votes
1answer
199 views

Reversing the vowels in a String

Given a string, reverse only the vowels present in it and print the resulting string. Input: First line of the input file contains an integer T denoting the number of test ...
1
vote
1answer
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, ...
5
votes
3answers
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 ...
16
votes
4answers
2k views

Leetcode 15. 3 Sum

Problem statement Given an array S of n integers, are there elements a, ...
2
votes
1answer
97 views

Anagram checking implementation

Given two strings, check whether two given strings are anagram of each other or not. An anagram of a string is another string that contains same characters, only the order of characters can be ...
4
votes
1answer
1k views

2D Maze solver using recursion in Python

A company I interviewed for sent me a coding problem to solve. The problem was to find a solution to a maze, not necessarily the shortest one. The input would be like so: ...
15
votes
2answers
3k views

Roman to Integer

I'm trying to get better as a programmer and would love any feedback on my code. Especially the section in the while loop. How could I make this more readable? What would your opinion as an ...
5
votes
3answers
128 views

Implementing an order system for a job interview

I have to implement a relatively basic order system in Java for part of the process of a job interview. At the moment I have working code that allows for the creation, and updating of orders for an ...
3
votes
2answers
127 views

Non repeating character in Java

Given a string s consisting of lowercase Latin Letters, find the first non repeating character in s. Input: The first line contains T denoting the number of testcases. Then follows ...
6
votes
4answers
2k 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 ...
4
votes
1answer
803 views

Rate calculation system for a code challenge

This code challenge was part of a interview process I had applied for, and from which I was discarded after this test. I'd like to hear what other people have to say, hopefully in deeper detail. The ...
3
votes
1answer
957 views

Counting unique words, numbers, or phrases

I was given the below scenario to write a java program by a Software company. I did my best and was well tested as well. They came back rejecting my application without giving any review comments. I ...
1
vote
2answers
120 views

Star Elements implementation in Java

Given an unsorted array. The task is to find all the star and super star elements in the array. Star are those elements which are strictly greater than all the elements on its right side. Super ...
1
vote
2answers
463 views

Find all root to leaf paths in binary tree

Description: Given a binary tree, return all root-to-leaf paths. Leetcode ...
2
votes
1answer
563 views

Find all k-sum paths in a binary tree

Description: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. Note: A leaf is a node with no children. Leetcode Code: ...
6
votes
1answer
580 views

Calculate implied volatility for options on stocks and futures with two models

I wrote a code for a quant finance job and they told me that, besides it worked, it was poorly written. I asked for a more detailed feedback but they did not send it to me. I paste it here with ...
0
votes
1answer
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 ...
2
votes
1answer
198 views

Find minimum depth in a binary tree

Description: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node ...
6
votes
1answer
433 views

Codility: MaxZeroProduct - complexity issues

My solution scored 100% correctness, but 0% Performance. I just can't figure out how to minimize complexity time. Problem: Write a function: ...
10
votes
4answers
14k views

Counting occurrences of each word in a sentence

I have been doing this test task for C# Developer role at UBS.London recently and have been rejected. No reason stated yet. Was wondering if you can take a look and provide feedback on what I can do ...
1
vote
2answers
143 views

Greater on the right side in Java

Given an array of integers, replace every element with the next greatest element (greatest element on the right side) in the array. Since there is no element next to the last element, replace it ...
1
vote
0answers
86 views

System on Chip Validator

With reference to my source files, published in the git repository soc-testing I did my best effort at coding, based on 30 years of experience, so I would like to know what I did wrong with my ...
5
votes
0answers
147 views

Function which would get the next `n` slots from the current time [closed]

I have attended an interview recently and my coding got rejected by the panel. I am new to Python and is mentioning my code below. Please help me improve the code quality or any bug: Question: Given ...
3
votes
1answer
224 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 ...
3
votes
3answers
348 views

Inventory allocation method

Recently I have attended an Interview with a firm. They gave me a task to complete. I have done it and tested it as well. But they rejected my code. Is the given code properly written? Is my coding ...
0
votes
2answers
1k views

Count the number of occurences of X's within a range in Java

Given an integer X within the range of 0 to 9, and given two positive integers as upper and lower bounds respectively, find the number of times X occurs as a digit in an integer within the ...
0
votes
2answers
524 views

Check if array contains contiguous integers with duplicates allowed in Java

Given an array of n integers(duplicates allowed). Print “Yes” if it is a set of contiguous integers else print “No”. INPUT: The first line consists of an integer T i.e. the number of test ...
1
vote
2answers
74 views

Count total set bits

Im am solving Count total set bits: Find the sum of all bits from numbers 1 to N. Input: The first line of input contains an integer T denoting the number of test cases. The first line ...