# Tagged Questions

95 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 ...
115 views

### Simplification of byte array comparison algorithm

I have an algorithm that evaluates in input byte[] with a source byte[]. Several conditions can be encountered: Match found No match found End of input array End of source array Input wildcard (*) ...
97 views

### Find two missing elements from a sorted array in given range

Looking for reviewers to suggest optimization and improvements, and to evaluate coding practices. final class Variables { private final int x; private final int y; Variables(int x2, int ...
84 views

### Find a missing numbers, single missing number and two missing numbers, from consecutive range

Contains 3 options. Given an input array Unsorted and consecutive range, and array is 1 element short. eg: range is 6-9, and array = [7, 8, 9] output should be 6. All conditions same as previous ...
53 views

### Merge 2 arrays, when one is larger and can accomodate smaller

How will you merge two sorted arrays, when The longer array has empty spaces to accomodate the second array. Complexity: O (items in longer + items in smaller). Request for making code concise, ...
169 views

### Finding greatest value in array smaller than x

Code review requested to make this code simpler, cleaner, and better. Input array is sorted. This program finds the greatest number smaller than x. So, in an array [10 20 30 40] and x = 25, the ...
285 views

### Review my sorting algorithm please!

I've been playing around and reading up on some sorting algorithms, and i decided to try writing my own.. It turned out to be quit fast (Compared to the others shown in the image below). I'm i'm very ...
89 views

### Missing element from array (D&C) - code design/aesthetic improvement

I am trying to implement in C/C++ a 'classical' Divide and Conquer algorithm which solves the following problem "Given an array of n-1 numbers (int) from 0 to n, find the missing number". I am using ...
263 views

### Remove specific consecutive element in array

I'm trying to reduce consecutive elements of array to one, but not for all values like: {3,0,0,0,3,3,3,0,0,0} => {3,0,3,0} but for specific one, in my example 0: {3,0,0,0,3,3,3,0,0,0} => ...
297 views

### Quicksort using pointers

As an exercise, I've written quicksort algorithm in C using pointers. Please comment and help me find the cases where it breaks (if any). void qsort(int *, int, int); void swap(int *, int *); void ...
296 views

### Find the 2 distinct highest values in an array

I want to know if there is a way to improve my code. It finds the two highest values in an array, and these numbers need to be distinct. I don't want to sort the values; I just want to find them. ...
49 views

### Code to find the proper index comparing 3 values for max one

I have an algorithm and the idea is to move over an array choosing as index the index of the neighboring cell that has the max value. I.e. if array[i + 1][j + 1] has the largest value among the 3 ...
542 views

### Partitioning Array

Problem: Given a randomly ordered array of n-elements, partition the elements into two subsets such that elements <=x are in one subset and elements > x are in the other subset. one way to do this ...
179 views

### Devise an algorithm of complexity O(N) finding No of 1's from a 2 dimensional matrix[N][N] containing 1's and 0's

Assume a 2d [n][n] Matrix of 1's and 0's/ All the 1's in any row should come before 0's/The number of 1's in any row i should be atleast the no of 1's row (i+1). find a method and write a c program to ...
215 views

### Java permutation function returns zero for some reason…? [closed]

The following code works in Python but seems to return zero in Java for some reason. Can you point out any errors? import java.util.ArrayList; import javax.swing.JOptionPane; public class Test { ...
607 views

### Find all single elements in an array

I am interested in printing all numbers that do not have a match in an array. Example: 1,3,4,5,3,4,5,5,6 result 1,5,6 Please review my solution bellow. What would be a much better way for this? Any ...
3k views

### The most repeated number in an array [closed]

I'm quite new with C++ and trying to write a program at which I should: take 20 numbers from the user, putting them in an array, writing a function to find the most repeated element, returning ...