Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [interview-questions]

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

0
votes
1answer
69 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 ...
2
votes
3answers
58 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 ...
0
votes
1answer
73 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
112 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
55 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
182 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
32 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
46 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
52 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
107 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
3answers
1k 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
61 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
133 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
50 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: ...
8
votes
2answers
195 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. ...
2
votes
1answer
337 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 ...
2
votes
1answer
76 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
49 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
72 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 ...
2
votes
0answers
49 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, ...
1
vote
0answers
32 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
129 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
53 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
43 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
102 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
84 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
228 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
75 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
89 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 ...
3
votes
0answers
53 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
192 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 ...
4
votes
1answer
142 views

Minimum swaps algorithm terminated due to timeout

I have been trying to solve this question. Given an unordered array consisting of consecutive integers [1, 2, 3, …, n], find the minimum number of two-element swaps to sort the array. I was able ...
6
votes
2answers
178 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 ...
2
votes
1answer
111 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? ...
5
votes
2answers
706 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 ...
5
votes
5answers
319 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 ...
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
427 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 ...
4
votes
2answers
317 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
143 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 ...
6
votes
8answers
3k views

Check if a string has all unique characters

This is a question from the book "Cracking the Coding Interview". Implement an algorithm to determine if a string has all unique characters What if you can not use additional data structures? I ...
3
votes
1answer
149 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
80 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 ...
2
votes
1answer
60 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. ...
3
votes
1answer
58 views

Thread-safe arraylist with get, put, add, remove functions

I am preparing for multithreading interview questions and I don't have much experience with multithreading. I referred some online article to come up with a solution. Is this solution appropriate? <...
0
votes
1answer
79 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 ...
2
votes
1answer
52 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
218 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: ...
13
votes
2answers
2k 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
117 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 ...