All Questions
Tagged with algorithm data-structures
9,246
questions
0
votes
1
answer
42
views
Kotlin data structure for efficient lookup of nested data
I am currently working on an application that needs to create a mapping between document pdfs and corresponding JSON data files. The files are coming from a third party so I have no control over their ...
0
votes
2
answers
55
views
How is my algorithm for stock span problem incorrect?
The question :
The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stocks price for all n days.
The span Si of ...
-1
votes
1
answer
72
views
Shuffle the Array - LeetCode problem. 2 pointers approach fails [closed]
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
53
views
Understanding Time complexity of nested sorting
I am solving this LeetCode problem 1636. Sort Array by Increasing Frequency:
Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple ...
0
votes
3
answers
55
views
Time complexity analysis of data structures
I got a bit confused about analzsis of data structure basic operation like inserting or deleting.
when I am asked about creating an data structure that support deleting operation, or inserting in O(1),...
-2
votes
1
answer
44
views
Given a number N find the number just smaller than N such that it has a given digit x present in it x times [closed]
You will receive an input number N in string format and also a number x. Your task is to find the largest number that is smaller than N and contains the digit x exactly x times.
For example: N = ...
2
votes
2
answers
82
views
Finding the subarray with the least median given a size K and an array of length N
I have been struggling the past month with this problem that was given to us on our course while I was upsolving it. The task is to find the window of size K with the least median in an array of ...
0
votes
0
answers
38
views
Finding Top Users with Common Records in a Growing Dataset
I’m working on a project where I have a large dataset containing billions of records. Each user can have one or more records, and each record can be associated with multiple users.
Given a specific ...
4
votes
0
answers
205
views
Finding repeating sequences with less than O(n^2) time complexity
Is it possible to find repeating sequences of any length (without complete overlaps) with an average time complexity less than O(n^2) ?
For example, take a string like this:
0 1 2 ...
0
votes
1
answer
69
views
Constructing Linked List in Rust from head to tail without unwrap
It is said that unwrap is unsafe and it should be avoided if possible.
While I was constructing a linked list, I found an unwrap inevitable.
My question is, is it possible to remove this unwrap or is ...
2
votes
0
answers
55
views
Most efficient way of determining if a subgraph of a graph is connected
Suppose I have a graph given by a Laplacian matrix $L$ corresponding to a regular discretization of $[0,1]^2$, meaning nodes $I={(i,j),\quad i,j=1,\dots,n}$ are connected with $(i+1,j),(i,j+1),(i-1,j),...
1
vote
1
answer
95
views
Why does the sliding window algorithm not work for this problem statement?
The question is regarding an algorithm which I'm using to solve a problem. The problem statement is: (or view it here)
"Given arrival and departure times of all trains that reach a railway ...
5
votes
1
answer
108
views
Minimal path on weighted tree query
Given a weighted tree with n vertices. there are q queries and for each query, you are given integers (u,k). find number of vertices v such that the smallest edge on the route from u to v is equal to ...
2
votes
1
answer
82
views
Modified Dijkstra - Time Complexity?
I am solving the Leetcode Problem 787. Cheapest Flights Within K Stops.
Basically this is single source shortest path, but with max k steps allowed. So, we can't use normal Dijkstra algorithm, where ...
2
votes
2
answers
105
views
How to locate the most sparse point within a defined 2D region?
The core of the problem is to algorithmically determine the coordinates of the point E that maximizes the distance to the nearest other point in the bounded 2D space.
For example, in the space defined ...