All Questions
8,196 questions
4
votes
1
answer
120
views
Algorithm to find the number of specific continuous substrings
I am trying to solve the following algorithmic problem:
Every day, Bob goes to work and does one of 26 possible tasks. The tasks are coded with the letters of the English alphabet from a to z. ...
4
votes
1
answer
228
views
Optimizing LeetCode's "Minimum Pair Removal to Sort Array II" Solution to Prevent Time Limit Exceeded Errors
I am working on the LeetCode problem 3510. Minimum Pair Removal to Sort Array II:
Given an array nums, perform the following operation any number of times:
Select the adjacent pair with the minimum ...
0
votes
3
answers
138
views
Fastest way to randomly shuffle an array based on probabilities in PHP? [closed]
I have an array with values and probabilities (or in PHP, keys and values):
Value Probability
John 3
Peter 2
Paul 1
I want to shuffle this array but have the order be influenced by the ...
2
votes
1
answer
76
views
is there any problem in the terms of time complexity in this code?
So today I was learning selection sort, and gain the concept how actually selection sort it working(i mean we add new element in the sorted array then check that element if it is on its correct ...
2
votes
1
answer
73
views
Target sum algorithm using Numpy
I have a numpy array of floats and a target sum. I am trying to find all possible combinations of elements that would add up to the target sum.
I am struggling to come up with anything computationally ...
6
votes
1
answer
106
views
Fastest way to find the smallest possible sum of the absolute differences of pairs within a single array?
By grouping all the items within an array into pairs and getting their absolute differences, what is the minimum sum of their absolute differences?
Example:
[4, 1, 2, 3] should return 2 because |1 - 2|...
2
votes
3
answers
122
views
How to calculate the gradient of an n-dimensional array of data in R
I feel like there must be some function in some package that does this, but for the life of me I cannot find one that calculates the gradient of an array of data points (not a function) by simply ...
7
votes
6
answers
430
views
How to move duplicates to the end of an array while preserving order in C?
I need to write a function in C that processes an array by moving all duplicate elements to the end of the array. The function should preserve the relative order of distinct elements, but the order of ...
-1
votes
1
answer
74
views
Collision of array elements
Is it feasible to design an algorithm like this? Specifically, is it possible to write a Python code for the following logic?
You have an array of numbers (e.g., 1533 consecutive numbers). It doesn't ...
2
votes
3
answers
66
views
I would like to modify the values of specific elements in a list in an efficient manner [closed]
How can I make the function more efficient?
This is all the test code I wrote:
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:flutter_test/flutter_test.dart';
...
3
votes
2
answers
105
views
In-place array compaction with least amount of shifting
I've been searching for an algorithm that can do array compaction with the least amount of movement of items. I know I can't go below O(N) and that's fine, but I'm not sure if even that's doable.
I'll ...
2
votes
3
answers
148
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) ...
4
votes
2
answers
155
views
How to Mark Repeated Entries as True Starting from the Second Occurrence Using NumPy?
Problem
I have a NumPy array and need to identify repeated elements, marking the second occurrence and beyond as True, while keeping the first occurrence as False.
For example, given the following ...
2
votes
2
answers
240
views
Increasing triplet subsequence - does this solution really work, and why?
I've been struggling with the LeetCode problem 334. Increasing Triplet Subsequence:
Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k ...
5
votes
1
answer
108
views
Efficient way to delete columns and rows from a numpy array using slicing and not np.delete
Would it be possible given an array A, bad row indices and bad column indices to use slicing to make a new array that does not have these rows or columns?
This can be done with np.delete as follows:
...