All Questions
1,460 questions
2
votes
3
answers
149
views
How to efficiently find the smallest missing positive integer in a large, partially sorted array?
I have a large array of integers that is partially sorted, meaning that some parts of the array are in order, but others are not. I need to find the smallest missing positive integer (greater than 0) ...
0
votes
1
answer
299
views
Effective hiking - dynamic programming
I got the following question today, and solved it suboptimally. I wanted to get some help how to get this to the most optimal solution:
The question is; A hiker needs to complete a lit of trails on ...
-2
votes
2
answers
142
views
Shuffle the Array - LeetCode problem. 2 pointers approach fails
I am trying to solve LeetCode problem 1470. Shuffle the Array:
Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].
Return the array in the form [x1,y1,x2,y2,...,xn,...
0
votes
1
answer
62
views
Checking a candidate majority element: Does my simplification work with all cases?
Here are the details of the problem:
Given a sorted array arr of N elements.
A majority element in an array of size N is an element that appears more than N/2 times.
The task is to write a function ...
2
votes
4
answers
154
views
Moving even elements to the front of an array while keeping relative order
public static void teePaarisPaaritud(int[] a){
teePaarisPaaritudRek(a, 0);
}
private static void teePaarisPaaritudRek(int[] a, int i) {
if(i == a.length-1) return;
if(a[i] % 2 != 0){
...
-1
votes
1
answer
53
views
A method to traverse in both permutation and combination
if i have an array for example array = [1,2,3,4] and i should have output like
1
2
3
4
1,2
1,3
1,4
2,3
2,4
3,4
1,2,3
1,2,4
1,3,4
2,3,4
1,2,3,4
i did try various methods but i doesn,t yield expected ...
1
vote
3
answers
180
views
Find sum of absolute difference
Given array of integers A and B. For each item in B, find the sum of absolute difference with A elements and build the result array.
Example:
A = [1,2,3]
B = [3,2,1,5]
**Result = ** [3,2,3,9]
...
0
votes
1
answer
317
views
most efficient way to compute f(n)^f(n) where f(n)=n^n and n has 15-20 digits
I was asked to implement the most efficient program in java to compute f(n)^f(n) where f(n)=n^n and for n with large number of digits(15-20). I have figured that binary exponentiation(exponentiation ...
0
votes
1
answer
74
views
Java Conversion issue - Int to string and again
I am trying to make an integer to string to make slicing operation but the program doesn't gives me any answer it always gives the empty arraylist and While I see the modulus function simply returns ...
1
vote
2
answers
105
views
is there a way to copy and shift small blocks of elements in an array to the left in a new grown array in java in o(log(n)) in a systematic way?
lets say we have an array which acts as an implicit binary heap, and we start with:
[0, 0, 0]
It slowly gets filled up to:
[3, 2, 3]
We will need to grow it, by copying it to a new grown array of size ...
1
vote
1
answer
78
views
Is this the correct implementation for finding duplicates in sorted arrays?
I've been working on an assignment that involves optimizing a duplicate finding algorithm for sorted arrays, and I'd like to get your thoughts on the implementation. Here's the code I've come up with:
...
-1
votes
2
answers
204
views
Want to know the Logic behind the code simple code
Given n boolean variables X1, X2, ..., and Xn, we wish to print all possible combinations of truth values they can assume. For instance,
if n = 2, there are four possibilities: true, true; true, false;...
0
votes
1
answer
80
views
How can I print the closest Point?
I have my program with the closest pair of point in a array of n (number inserted by the user) points, I created the algorithm for it and it works giving back the minor delta (distance between points),...
-1
votes
3
answers
933
views
Product of Array Except Self (Leetcode)
class Solution {
public int[] productExceptSelf(int[] nums) {
//Approach: Using prefix and postfix
//Idea: Just find prefix and postfix product and keep them in the ans ...
3
votes
3
answers
784
views
Leetcode 2161: Partition array according to given pivot
I'm currently solving LeetCode problem 2161. Partition Array According to Given Pivot:
You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following ...