325 questions
2
votes
1
answer
101
views
Cyclic Sort Implemenation
I was just trying to implement cyclic sort after watching the theory part of a YouTube video (https://youtu.be/JfinxytTYFQ?list=PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ&t=889).
I came up with the below ...
2
votes
1
answer
4k
views
Minimum numbers of operation required to make an array bitonic [closed]
I am trying to solve this code challenge:
Given an array arr of n integers, in a single operation, one can reduce any element of the array by 1. Find the minimum number of operations required to ...
2
votes
1
answer
61
views
Efficient Algorithm for Finding the Longest Increasing Subsequence [duplicate]
I'm working on a project where I need to find the longest increasing subsequence (LIS) from a given array of integers. However, the array can be quite large, so I'm looking for an efficient algorithm ...
0
votes
3
answers
198
views
What is the exact time complexity of this algorithm?
I attempted to solve the problem at this HackerRank link (https://www.hackerrank.com/challenges/diagonal-difference/problem?isFullScreen=true) Given a square matrix, calculate the absolute difference ...
0
votes
2
answers
81
views
Diff an array of objects so that it matches another without recreating any valid objects
Let's say I have 2 arrays each of which holds a few different objects
class Object1 {}
class Object2 {}
class Object3 {}
class Object4 {}
class Object5 {}
class Object6 {}
const arrayA = [
new ...
-1
votes
2
answers
82
views
Recursion method is invoked even after loop condition is met
public int removeMin(Integer[] arr, int count) {
Integer[] tempArr = new Integer[arr.length -1];
int index = 0;
for (int i = 1; i<arr.length; i++) {
tempArr[index] = arr[i] ...
0
votes
1
answer
315
views
Maximum sum of two elements
You are given two arrays each with n integers. Find the maximum sum of two elements. You have to choose one element from the first array, one element from the second array and their indexes have to be ...
1
vote
1
answer
85
views
Inserting elements in a specific positions in the existing array
I have a List and Map as below,
val exampleList = List("A","B","C","D","E","A","L","M","N")
val exampleMap = ...
0
votes
2
answers
50
views
trying to adjust addition function to a subtraction function
I have this function:
static int[] AddArrays(int[] a, int[] b)
{
Array.Reverse(a);
Array.Reverse(b);
int[] result = new int[Math.Max(a.Length, b....
2
votes
1
answer
229
views
Efficient way of approaching the Subset Sum Problem with very large input sets
The problem I am facing:
I need to find a way to deal with very large sets (3 to 10000000) of positive and negative ints, this seemed relatively impossible based off of previous experiments.
However, ...
1
vote
1
answer
2k
views
Which time-complexity is better O(logM + logN) or O(logM.logN)?
I tried the binary search on the 2D matrix and I got the solution which gives the time compexity to be the O(logN.logM). There exist already a solution which performs it in log(MN)
time. I Only want ...
2
votes
2
answers
2k
views
Is there any practical use case for Sleep Sort?
This is one of the most unique and fun sorting algorithms on planet earth, in which the time required to complete sorting depends on the size of each individual element rather than the number of ...
-1
votes
1
answer
826
views
What is the Space complexity of initializing 2D array in a function that receive 2D array as input?
I was solving a leetcode problem ,
and wanted to find the space complexity[1] of a function that receives a 2D array of size nxn, and in the function I initialize a new 2D array of size (n-2)x(n-2)
...
0
votes
1
answer
220
views
MovingSum of list of integers
I want to calculate the moving sum of a list of integers with a window of size 3. I have a class as such:
class MovingSum:
def __init__(self, window=3):
self.window = window
def ...
-2
votes
1
answer
765
views
Convert array of paths into a Tree in JavaScript [closed]
Given this input:
const paths = ["src", "src/components", "src/components/index.ts", "src/utils", "src/configuration/config.ts", "another/file.ts&...
1
vote
2
answers
94
views
Algorithm for finding a set of N items based on percentages of how many times an item may appear
Let's say I have M boxes of different colors and sizes. I need to find a set of N boxes that contain different combinations of colors and sizes.
For example, the user could say they want the final set ...
0
votes
1
answer
166
views
I am having trouble visualizing sorting algorithms
I am trying to visualize a sorting algorithm with react, my algorithm works fine but i want to link it to divs on the DOM that change their height as the sorting algorithms sorts a given array, i have ...
2
votes
2
answers
2k
views
Euclidean distance or cosine similarity between columns with vectors in PySpark
I have a Spark dataframe in the following form:
> df1
+---------------+----------------+
| vector1| vector2|
+---------------+----------------+
|[[0.9,0.5,0.2]]| [[0.1,0.3,0.2]]|
|[...
0
votes
1
answer
89
views
Comparing Two Lists, Updating if Different
I have a program written in JavaScript that runs CRUD operations depending if the items in one lists are different from the other. Basically comparing two lists, main list and mirror list. The ...
0
votes
2
answers
58
views
Algorithm not functioning for sort squared array based off of input
I'm working on building an algorithm that sorts in place for an array of nondecreasing integers, and it's not passing some of my tests. I was wondering why? I've included a sample input and output as ...
1
vote
1
answer
242
views
How to convert 3-dimensional array of fixed size to a reference-style?
I work with 3-dimensional arrays of fixed size. For the first time I used passing by value.
fn some_func(matrix: [[[f64;Z];Y];X]) {// body}
fn main() {
let m = [[[0.0;Z];Y];X];
some_func(m);
}...
2
votes
0
answers
1k
views
Minimum adjacent swaps to group equal elements in an array
Given an array L containing N elements, from an alphabet of M distinct elements, is there an effective way to calculate the minimum number of swaps of two adjacent elements such that we group all the ...
1
vote
1
answer
152
views
Why does the method not compute maximum greater than 65537?
public int longestConsecutive(int[] nums) {
Map<Integer, Boolean> numMap = new ConcurrentHashMap<>();
Map<Integer, Integer> maxMap = new ConcurrentHashMap<>();
...
0
votes
1
answer
249
views
find maximum GCD of an array of triplets
you are given an array of triplets of size N, we have to choose one number from each triplet, forming a new array of N size, such that the GCD of the numbers in the new array is maximum.
example:
an ...
0
votes
2
answers
208
views
Replace all occurances of a number in a matrix python
The input is a multi-line string containing the matrix:
input = '''22 13 17 11 0
8 2 23 4 24
21 9 7 16 7
6 10 3 7 5
1 12 20 15 19'''
I have to replace all the occurrences of, let's say 7 ...