Skip to main content
Filter by
Sorted by
Tagged with
2 votes
1 answer
110 views

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 ...
Nishanth K N's user avatar
7 votes
1 answer
409 views

I came across LeetCode problem 137. Single Number II: Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and ...
Gopika J's user avatar
  • 101
2 votes
1 answer
4k views

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 ...
systummm's user avatar
-3 votes
1 answer
87 views

I'm going out of bounds somewhere while iterating a very long string but I can't seem to find out where? import java.util.*; public class Solution { //Helper function to reverse words in string ...
hedgein's user avatar
2 votes
1 answer
74 views

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 ...
Navodya Vidumini's user avatar
0 votes
0 answers
66 views

I am a math student and I have been asked to help grade answer sheets for an Algorithms course as one of my professors is unwell. While I am quite familiar with combinatorial algorithms, I am not well ...
Umesh Shankar's user avatar
0 votes
3 answers
206 views

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 ...
Mário Alfredo Jorge's user avatar
-1 votes
1 answer
193 views

#include <iostream> using namespace std; const int TMAX = 2000000; int num_chupiguays(const int a[], int n) { int suma = 0; int resul = 0; for (int i = 0; i < n; i++) { ...
Ola's user avatar
  • 13
0 votes
2 answers
82 views

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 ...
Charlie Martin's user avatar
0 votes
1 answer
139 views

I have written a function that makes an array unique, but I don't quite understand how the time complexity works here. Here's my whole program: #include <stdio.h> #include <stdlib.h> #...
krotovukha's user avatar
-1 votes
2 answers
86 views

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] ...
ansh87's user avatar
  • 3
1 vote
0 answers
65 views

For one of my assignment, I am asked to implement a radix sort algorithm. Here is the code that was written so far: class RadixSort: def __init__(self): self.base = 7 self....
Sakops's user avatar
  • 34
0 votes
1 answer
332 views

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 ...
Tomek Swiecki's user avatar
0 votes
1 answer
192 views

I am new to algorithms and data structures. Thus, I joined LeetCode to improve my skills. The first problem is to propose an algorithm whose time complexity is less than O(n^2). I used the code ...
Ne2j's user avatar
  • 3
1 vote
1 answer
93 views

I have a List and Map as below, val exampleList = List("A","B","C","D","E","A","L","M","N") val exampleMap = ...
Hima_93's user avatar
  • 51
0 votes
5 answers
572 views

Sort an array by number of set bits. For example, Input: arr = [0,1,2,3,4,5,6,7,8] Output: [0,1,2,4,8,3,5,6,7] example 2 Input: arr = [1024,512,256,128,64,32,16,8,4,2,1] Output: [1,2,4,8,16,32,64,...
codepractice's user avatar
0 votes
2 answers
59 views

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....
Punzicul's user avatar
0 votes
1 answer
59 views

so i have this function: static int[] AddArrays(int[] a, int[] b) { int length1 = a.Length; int length2 = b.Length; int carry = 0; int ...
Punzicul's user avatar
2 votes
1 answer
241 views

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, ...
Talon Van Vuuren's user avatar
1 vote
2 answers
166 views

here is an array presented id: 0, parent: 'p1', children: [ { id: 1, parent: 'p2', children: [ { id: 3, ...
gyan mishra's user avatar
1 vote
1 answer
2k views

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 ...
Mohit Ashliya's user avatar
1 vote
2 answers
201 views

After a while, I was trying to implement quickSort on my own. To me the implementation looks fine, but some test cases are apparently failing. class MyImplementation { public int[] sortArray(...
John Doe's user avatar
  • 2,942
2 votes
2 answers
2k views

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 ...
Chinmay Krishna's user avatar
-1 votes
1 answer
126 views

I'm almost a beginner programmer that wants to learn how to write algorithms.I just wrote a program that finds the shortest subarray(subset) in an array, whose sum of indexes in the given array equals ...
Stiffo's user avatar
  • 7
-1 votes
1 answer
856 views

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) ...
Hasan S.'s user avatar
0 votes
0 answers
47 views

I am trying to solve a maze using Eller's Algorithm and Recursive Division, Although I know that these two Algorithms can be used to generate a maze but is it possible to solve one using either Eller'...
Fahad's user avatar
  • 1
0 votes
1 answer
274 views

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 ...
turtle_in_mind's user avatar
-1 votes
2 answers
109 views

When I Run my code And take input of array in ascending order from user the function which i have made runs and if the i search the middle number from array to find its location the code runs ...
temporary's user avatar
-2 votes
1 answer
774 views

Given this input: const paths = ["src", "src/components", "src/components/index.ts", "src/utils", "src/configuration/config.ts", "another/file.ts&...
User's user avatar
  • 151
2 votes
1 answer
151 views

I have an array p with integers . I need to compute d[i, j] for all (i, j) : i<j , where : d[i, j] = max (p[b] - p[a]) , i<=a<b<=j I know how to solve this for d[1,n] in O(n) . But for ...
tonythestark's user avatar
1 vote
2 answers
96 views

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 ...
Mike R's user avatar
  • 961
0 votes
0 answers
144 views

I have an array that can have a really large size holding values I need to decrement to 0. And I have a total amount I can decrement this array by. The problem is I want to decrement it round robin ...
Mashiron's user avatar
0 votes
1 answer
182 views

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 ...
Coder apprentice's user avatar
0 votes
2 answers
307 views

new Array(n) will create an array of n * undefined, so why can't you use new Array(n).map((_, index) => index) function to get [0, 1, 2 ..., n-1 ] What about arrays like this? I know that new Array(...
david relo's user avatar
2 votes
2 answers
2k views

I have a Spark dataframe in the following form: > df1 +---------------+----------------+ | vector1| vector2| +---------------+----------------+ |[[0.9,0.5,0.2]]| [[0.1,0.3,0.2]]| |[...
Hilary's user avatar
  • 485
0 votes
1 answer
411 views

I'm trying to figure out how to do a value shift in an array by one value incrementally in Java, without using a second array to store values. Is there a way to just have a couple (1-3ish) of values ...
Sirgeorge's user avatar
  • 147
0 votes
1 answer
92 views

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 ...
Ian Matsumoto's user avatar
0 votes
1 answer
340 views

I'm attempting to solve the merge overlapping intervals problem and have the working solution below. However there's a piece of logic that im having problems understanding. Namely the part where the ...
Frisbetarian-Support Palestine's user avatar
0 votes
2 answers
62 views

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 ...
Candace's user avatar
  • 53
1 vote
3 answers
820 views

Is there a standard algorithm in the library that does the job of the following for-loop? #include <iostream> #include <vector> #include <iterator> #include <algorithm> int ...
digito_evo's user avatar
  • 3,725
1 vote
1 answer
255 views

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); }...
Alexander Fyodorov's user avatar
-1 votes
4 answers
1k views

I have an array of this shape: [ { unique: 8, views: 24, name: "https://l.instagram.com/", sec: 5.39, }, { unique: 2, views: 20, name: "", sec:...
lisa's user avatar
  • 27
2 votes
0 answers
1k views

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 ...
rmlb's user avatar
  • 21
0 votes
1 answer
187 views

I am trying to solve cses salary queries (https://cses.fi/problemset/task/1144/) Question: I will make a frequency array of salaries and I will use coordinate compression but while update I have to ...
bharat aaryavrat's user avatar
1 vote
1 answer
163 views

public int longestConsecutive(int[] nums) { Map<Integer, Boolean> numMap = new ConcurrentHashMap<>(); Map<Integer, Integer> maxMap = new ConcurrentHashMap<>(); ...
user avatar
0 votes
2 answers
341 views

I recently got this question (paraphrased below) in a practice interview test and it still stumps me: Given a 2d array A, generate a list of row-wise 1d array permutations from it. A = [ [1], ...
polarSyndicate's user avatar
0 votes
1 answer
288 views

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 ...
ayushi's user avatar
  • 63
1 vote
2 answers
94 views

I have the following array: [1,2,3,4,5,6,7,8,9] And I have to return based on a group and step parameters the following values E.g.: group = 3; step = 3; [ [1,2,3], [4,5,6], [7,8,9], [1,2,3] ] group =...
mihaij's user avatar
  • 95
0 votes
2 answers
210 views

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 ...
Abhinav's user avatar
  • 119
0 votes
1 answer
497 views

They use same array: QUICK SORT Time: 3159 miliseconds (array length 10K) Bubble SORT Time: 1373 miliseconds (array length 10K) I'm trying to compare time of the sorting using quick and bubble sort ...
dimitri's user avatar
  • 149

1
2 3 4 5
7