Questions tagged [interview-questions]
This tag is for questions that came up in an interview.
935
questions
1
vote
4
answers
104
views
Find first and last matches on a sorted list
I needed a function to find the first and last indices into a sorted list corresponding to a given value (roughly similar to C++'s equal_range()).
This is the ...
2
votes
1
answer
66
views
Golang solution to CTCI 1.2: Check whether two strings are permutations of each other
Just started learning Go recently. Did some questions from Cracking the Coding Interview book. Wrote the solutions in Go. Let me know what you think.
https://github.com/samjingwen/ctci
Below is ...
9
votes
6
answers
3k
views
Conway's Game of Life Object oriented implementation in Java
I have designed Conway's Game of Life in Java, the solution follows Object Oriented design and paradigm, please review and let me know the feedback
Class Cell
Cell ...
1
vote
1
answer
79
views
Parse a log file into separate column files
This is a follow-up to https://stackoverflow.com/questions/71194832/converting-json-based-log-into-column-format-i-e-one-file-per-column .
My task is to optimize this code whose function is to convert ...
1
vote
1
answer
99
views
Another Vending Machine implementing State Pattern
I previously asked for a review for a Vending Machine implementing State Pattern in this linked post.
And received an answer from @radarbob. The code below is my revised attempt based on some of @...
5
votes
1
answer
166
views
Vending Machine implementing State Pattern
I was asked to implement a Vending Machine in a recent interview coding challenge. My attempt at a solution is based on the state pattern.
I would like to get some code reviews on this bearing in mind ...
2
votes
0
answers
37
views
Coding style of solution of the "Regular Expression Matching" problem on LeetCode
"Regular Expression Matching" is a hard problem on LeetCode (problem #10):
Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:
...
4
votes
2
answers
737
views
Coding style and idiomaticity of solution to the Word Search II problem on LeetCode
"Word Search II" is a hard problem on LeetCode (problem #212):
Given an m x n board of characters and a list of strings words, return all words on the board.
Each word must be constructed ...
1
vote
1
answer
62
views
Reverse a sublist of a singly-linked master list in constant space and maximum of one pass (Java)
So I found this funky programming challenge somewhere on Quora. The idea is to take the head of a singly-linked list, and reverse a specific sublist. The requirements are:
runs in constant space,
...
3
votes
3
answers
129
views
Find smaller angle between minute and hour hands of clock
In this code the angle between the minute and hour hands of an analog clock are found and calculated and the smaller angle between them returned. This code works perfectly and I am getting back the ...
4
votes
1
answer
122
views
Return the biggest loss a client made from prices list
A hiring company gave me the following challenge:
We want a function which accepts a very large list of prices (pricesLst) and returns the largest possible loss a ...
2
votes
0
answers
39
views
Proper way of using redux and props
I made a weather app in react and redux for an interview. The response was that I didn't use redux properly, and that it has unnecessary props. I'm not sure what they meant.
The app is on github https:...
4
votes
4
answers
1k
views
Model animals using inheritance in Java, revised
Yesterday I posted my first solution to an interview problem here. I am now aware that I have many weak spots in Java and need to do extensive review before tackling any more interviews. Having said ...
1
vote
1
answer
110
views
Model animals using inheritance in Java
I was assigned the following problem:
You've gone back in time to 500BC Athens and Socrates wants you
to build him an app to help classify animals.
Build the classes ...
1
vote
1
answer
314
views
Printing odd and even numbers in separate threads C++
I recently saw a youtube video on printing even and odd numbers from 0 to 100 in Java. https://www.youtube.com/watch?v=eRNTx8k5cmA
Thread 1 prints even numbers and thread 2 prints odd numbers. Both ...
3
votes
2
answers
166
views
Check for max value in stack
Got this problem in a coding interview -
Get the max value of a stack in O(1).
The stack contains numbers only.
Please review my solution.
...
2
votes
3
answers
87
views
Find the 'n' most frequent words in a text, aka word frequency
I'm doing freeCodeCamp's Coding Interview Prep to improve my JavaScript skills. This challenge is called "Word Frequency", and is based on the Rosetta Code's entry of the same name.
The ...
2
votes
2
answers
204
views
Fake Interview Scenario: Hangman
For a fake interview I decided to write Hangman. The first question I have is when reviewing someone's code for a job interview is it more important to write something short and sweet that gets the ...
0
votes
1
answer
66
views
Hackerrank Gridland Metro - using Interval Cover Solution
Hi there I was hoping to get a better grasp of greddy algorithms while trying to solve this problem: Hackerrank: Gridland Metro and I was trying to apply an algorithm where each grid could be ...
4
votes
3
answers
584
views
Compute shortest path in undirected graph
In a recent coding interview I was asked to write a program which takes as input two text lines:
The first one represents a graph, formatted as a sequence of undirected edges like ...
0
votes
2
answers
680
views
Interview: Drug Analyzer class
the introduction is this:
You are a member of a biotechnology programming team that is responsible for creating a system for lab technicians, which will assist them with drug analysis.
Your goal is ...
5
votes
1
answer
554
views
Designing an URL Shortener
Recently I was assigned a URL shortener design problem while interviewing with a well known organization. Here is the exact problem statement:
Build a simple URL shortener service that will accept a ...
1
vote
1
answer
128
views
Square Spiral Matrix in Javascript
I've been grinding some Leetcode for an interview coming up and just completed Square Spiral in Javascript.
Looking for feedback on performance. This ranked faster than 58% of submissions, would there ...
1
vote
1
answer
110
views
Is My Controller too Coupling?
To put it in context, I had the assignment to do for a job interview in Node.JS, which basically making CRUD with products (and it have certain conditions).
The assignment was well-understandable, and ...
6
votes
1
answer
1k
views
friend locator app
I was rejected after a tech screening for the following code.
I mainly struggled to make the code 'production ready'.
I was running out of time so I did not create a class for testing.
How could I ...
2
votes
2
answers
94
views
Print Binary coded decimal Numbering of a given input number
Example 1
input:3
output:0011
Example 2
input : 15
output: 1111
in the below example code 15 is input.
I have taken 8 4 2 1 as array for Binary coded decimal numbering
this code is working as ...
3
votes
3
answers
1k
views
Printing rotations of an array 7 times
Loop through a given array 7 times and print the following output:
int[] arr = { 9, 2, 7, 4, 6, 1, 3 };
...
0
votes
2
answers
69
views
React Native screen to add a city to a weather app using a REST API
In a recruitment process, the company gives me a project to do in react native. I finished all the tasks. But company gave me a feedback and said that your project was good, but you did not apply best ...
3
votes
2
answers
465
views
Function that receives a string fraction and has to return said fraction reduced
I got this exercise on a job interview and i'd like to know how can i improve my code.
Exercise:
Create a function that returns a reduced version of a fraction.
Examples
Reduce("4/6") = &...
1
vote
0
answers
84
views
Find the number of carry operations needed to add two numbers digit by digit
I don't know if my test cases at the bottom cover every case, or if my mathematical logic in the reducer function is exactly right (referring to the math that starts with ...
2
votes
2
answers
77
views
LeetCode Reverse Nodes in k-Group
Link: https://leetcode.com/problems/reverse-nodes-in-k-group/
Problem description:
Given a linked list, reverse the nodes of a linked list k at a time
and return its modified list.
k is a positive ...
3
votes
1
answer
52
views
Simple command line API client for getting quotes
Was given a take-home test as part of a job interview, which I failed due to a supposed lack of tests, logging, error handling and packaging. But I did touch upon all of these.. suggested time spent ...
1
vote
1
answer
231
views
C# Coffee Machine
I saw this post and tried to do my attempt. This is the requirement of task:
Design a coffee machine which makes different beverages based on set
ingredients. The initialization of the recipes for ...
3
votes
1
answer
197
views
Python script to parse XML file into Json
How are you doing? I have to make a script to parse an xml input file to a json file. I tried to do my best, but it will be nice if you could check it and help me to improve it. The idea is that I don'...
1
vote
2
answers
516
views
InterviewBit Problem: Stringoholics
I am trying to solve https://www.interviewbit.com/problems/stringoholics/ InterviewBit problem.
Problem Statement:
You are given an array A consisting of strings made up of the letters
‘a’ and ‘b’ ...
4
votes
1
answer
165
views
Randomly rearrange table rows without unnecessary reflows
I recently completed a coding challenge for a company that did not get me to the next stage.
They were kind enough to provide the following feedback:
The coding assignment does not match what we are ...
9
votes
5
answers
2k
views
Unit test for a maximum-finding function
A while ago, I got this question as a part of an interview test which asked to write a function to find the biggest number in a vector and write all the unit tests required to show that the code works ...
2
votes
0
answers
36
views
Find all of the paths that lead to the minimum sum [closed]
"Find minimum path sum" in a 2D grid, is a very popular question which is solved by dynamic programming. But what if instead of the minimum sum value, we return all the actual paths that ...
2
votes
0
answers
99
views
Cron expression parser
Problem
Write a command line application or script which parses a cron string and expands each field
to show the times at which it will run.
~$ your-program "*/15 0 1,15 * 1-5 /usr/bin/find"...
0
votes
1
answer
1k
views
Implement an algorithm for a room cleaning robot
I wanted to ask this question to my interview candidates, hence wanted to first give it a shot to see if this is doable in 45 mins. Here's the code that I was able to come up with in 45 minutes. Can ...
2
votes
5
answers
166
views
FizzBuzz solution
I'm preparing for junior developer interviews and am trying to come up with a more interesting/versatile solution to FizzBuzz than I've done in the past. Do you have any ideas of how I might DRY this ...
2
votes
0
answers
39
views
Rainfall challenge: procedural implementation
This evening I have seen the text of the Rainfall Challenge posted seven years ago by Hunter McMillen. I did not look at his solution (besides, I have no clue about perl), but I was intrigued by the ...
2
votes
1
answer
449
views
Implementation of a ticket queue system in JavaScript
I got this question during an interview. The question itself was very open-ended - it asked me to implement a ticket queue system, where by default it would have 3 different queues to hold tickets ...
3
votes
2
answers
82
views
Count edit distance
I have implemented a C code in order to answer an interview question. I would be appreciated if someone would improve the code. Task is an easy, however I want to achieve best efficiency in terms of ...
2
votes
2
answers
71
views
remove kth last element from singly-linked list - Follow up
This code is a revised version of implementation which asked for an improvement. Original question is asked here:
remove kth last element from singly-linked list
credits to: Toby, Andreas, Arkadiusz
...
0
votes
2
answers
165
views
remove kth last element from singly-linked list
I have implemented a code to solve following problem. I would like to improve the code efficiency.
Pardon if I just printed out the result.
Code has O(N) time and constant space complexity.
Given a ...
2
votes
1
answer
125
views
Find minimal modulo-sum of pairs from two lists
Recently I appeared for an job challenge organised on HackerEarth.
Question:
There are two teams T1 and T2. Power of each player is represented in array. The rules of game are as follow.
There are ...
3
votes
1
answer
222
views
strstr implementation with python and sets
Please review my strstr implementation in terms of time/space efficiency and overall readability. I am preparing for a coding assessment coming up as I am looking to pivot my career from Physics to ...
2
votes
0
answers
57
views
Find room required for lectures
I have implemented a code to resolve following interview question. Please advice how it can be improved folks. Thanks in advance.
Given an array of time intervals (start, end) for classroom lectures
(...
2
votes
0
answers
75
views
Find the largest contiguous sum of two or more integers in an array of positive or negative integers?
I received an interview question: Find the largest contiguous sum of two or more integers in an array of positive or negative integers.
I wrote a brute force solution, which is slow at O(n^2). Is ...