All Questions
12 questions
2
votes
2
answers
112
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 };
...
2
votes
1
answer
2k
views
Rotate matrix 90 degrees
I recently did problem 1.7 Rotate Matrix in Cracking the Coding Interview. I realized my code is very different than what is in the book and also from what I'm finding online (I'm having trouble ...
6
votes
3
answers
15k
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 ...
5
votes
3
answers
135
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:
...
2
votes
1
answer
3k
views
Count the number of times a particular number appears in a sorted array of integers
I had an interview question awhile back that went more or less as follows:
You have a sorted array of integers representing the ages of every person living on earth. There's a single entry in the ...
2
votes
1
answer
1k
views
Find the contiguous subarray within an array (containing at least one number) which has the largest sum
Interview Q: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
For example: Given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [...
2
votes
3
answers
470
views
Minimum element in a sorted rotated array
A sorted array [0,1,2,3,4,5] when rotated n times (3 times in this case) becomes [3,4,5,0,1,2], meaning elements in the front move to the end. The code below finds the minimum element in this array, ...
17
votes
5
answers
4k
views
Given a sequence of positive integers A and an integer T, return true if a continuous sequence of A sums up to exactly T
Here is the source of the question, and my solution is below.
Did I determine the worst case correctly?
If you find any input where it doesn't work, please let me know.
...
7
votes
2
answers
1k
views
Finding pairs of numbers within A that add up to N
I am working on an interview question from Amazon Software Interview:
Given an integer N and an array of unsorted integers A find all pairs of numbers within A which add up to N
I have a working ...
4
votes
3
answers
2k
views
Removing duplicates from an array
I recently wrote this JavaScript algorithm for removing duplicates from an array as part of a job interview process, but was turned down for the position after submitting the code. I didn't receive ...
7
votes
3
answers
11k
views
Find elements occurring even number of times in an integer array
I came across an interview question, which is like this:
You have an array of integers, such that each integer is present an odd number of time, except 3 of them. Find the three numbers.
I tried ...