Skip to main content
Filter by
Sorted by
Tagged with
6 votes
1 answer
276 views

I'm working on a problem where I need to count, for each possible common difference D, the number of contiguous subarrays whose elements can be rearranged to form an arithmetic progression with common ...
YAR's user avatar
  • 63
-3 votes
1 answer
164 views

The algorithm I've written for an assignment is closely related to this monotonic stack approach https://www.geeksforgeeks.org/dsa/next-greater-element/ Best case: n pushes → Time complexity: O(n) ...
user29898's user avatar
Best practices
0 votes
3 replies
58 views

So I have a function that I used to compare audio fingerprints with a few thousand audio fingerprints stored in a postgresql. What I did basically was: def my_function(cur: Cursor, threshold: ...
d6u9d12e's user avatar
-5 votes
1 answer
80 views

Say I have an algorithm that runs in O(N*M + N + M). Say that although M can vary, it can only be between 1-20. For asymptotic complexity is M treated as a constant? Because you can't really take the ...
user31685420's user avatar
2 votes
3 answers
106 views

Let's say I have this pseudocode: int n = 100 for (int i = 1; i<=n; i++) System.out.println("Hello!"); for (int j = 1; j<=n; j++) System.out.println("World!!!"); end ...
ALFIAN BIN ABDUL HALIN  FSKTM's user avatar
0 votes
1 answer
67 views

Considering elements as a list of objects (already loaded in memory, not a DB query) and given the following portion of code: var filteresElements = elements.Where(el => el.Flag == true).Select(el....
hello-there's user avatar
2 votes
1 answer
302 views

There is a row of toys, where each toy is represented as either: 1 → red toy (needs to be painted blue), 0 → blue toy (already painted). An integer k is given. An operation can be performed as ...
CodeCrusader's user avatar
-1 votes
4 answers
159 views

I'm solving the "3Sum" problem where I need to find all unique triplets in an array that sum to zero. Here’s my brute-force Java code: public List<List<Integer>> threeSum(int[] ...
Ghanshyam dubey's user avatar
4 votes
2 answers
273 views

int k = 0; for (int a = n; a >= 1; a /= 2) for (int b = a; b >= 1; b--) k++; cout << k; I would say that the answer is O(n), but the book where I have found the exercise says that ...
Andrei Morgovan's user avatar
1 vote
2 answers
210 views

Suppose we want to generate a 5-digit unique student ID i.e. there are N = 100,000 possible values (from 00000 to 99999). What is the big O of the algorithm below? - while True: - Generate a random ...
Paolo Tormon's user avatar
4 votes
2 answers
132 views

I have a large directed graph (not a DAG) with about 26,000 nodes and 86,000 edges. I want to find all possible simple paths (no repeated nodes) from one given node to another. How difficult or ...
jd singh's user avatar
-3 votes
2 answers
92 views

I have a function of following form that I would like to know the time complexity of: recursiveFunction(List<Input> list, int leftIndex, int rightIndex){ if(rightIndex <= leftIndex){ ...
D159's user avatar
  • 409
-4 votes
1 answer
83 views

I have a function of following form that I would like to know the time complexity of: recursiveFunction(List<Input> list, int leftIndex, int rightIndex){ // If Terminating condition of ...
D159's user avatar
  • 409
0 votes
1 answer
70 views

I was doing leet code and came across https://leetcode.com/problems/two-sum/description/, which I've tried solving with a seen counter using hashmap. Below is the code: class Solution: def twoSum(...
jai's user avatar
  • 1
-2 votes
1 answer
126 views

I have an algorithm that is implemented by the following state table for a Turing machine: 𝑞1 𝑞2 𝑞3 0 0R 𝑞1 1L 𝑞3 0L 𝑞3 1 1R 𝑞1 0L 𝑞2 1L 𝑞3 _ _L 𝑞2 1S 𝑞0 _3 𝑞0 I want to determine the ...
Muhab Joumaa's user avatar
0 votes
1 answer
108 views

I'm looking at one of the solutions to the programming problem: Partition a Set into Two Subsets of Equal Sum. The programming problem: Given an array arr[], the task is to check if it can be ...
charactersum's user avatar
1 vote
1 answer
153 views

I'm trying to prove time complexity of merge sort algorithm in Isabelle HOL: theory Merge_Sort_Time imports Complex_Main "HOL-ex.BigO" begin fun merge :: "'a::linorder list ⇒ 'a list ...
Denis's user avatar
  • 1,325
4 votes
2 answers
187 views

What is the time complexity of the following code in C#? array.Order().Take(k).ToArray(); Will LINQ treat this as QuickSelect? Or, will it perform full array sorting with the complexity O(n log n)?
Andrei's user avatar
  • 1,226
0 votes
1 answer
164 views

I know that it's a never-ending question that comes back every now and then, but I'm really confused about these two. This is what I understand about them. In theory: LinkedList is faster at adding ...
sebkaminski16's user avatar
1 vote
1 answer
89 views

Reading up on backtracking led me to a page on geeksforgeeks.org about solutions to the n-queens problem. The first solution is introduced as the "naive approach" that generates all possible ...
retpoline's user avatar
2 votes
3 answers
119 views

My task is simple, i have a binary file that needs to be split into 8byte chunks where first 4bytes contain data (to be decoded in later step) the 2nd 4byte contain an int (time offset in ms). Some of ...
dermoritz's user avatar
  • 13.1k
2 votes
1 answer
166 views

I am trying to solve this question in O(N^3) time complexity but unable to get the right answer in C++. The question states: Design a function that takes in >=4 points and returns the number of ...
Ridwan Chowdhury's user avatar
1 vote
1 answer
67 views

I'm trying to determine the time complexity of the following code. It has a nested loop structure, and inside the inner loop, a recursive function is called. I want to understand how the recursive ...
Malik ZiA's user avatar
2 votes
0 answers
37 views

Whether it is BFS or DFS, is it (MN)^(MN)? There're M*N nodes and, in the worst case, all the nodes have edges between each other.
Pasha's user avatar
  • 1,988
7 votes
3 answers
448 views

I was attempting LeetCode question 128. Longest Consecutive Sequence: Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an ...
Samson's user avatar
  • 2,038
2 votes
2 answers
127 views

I was doing this question on Codeforces (2057B - Gorilla and the Exam) where I had to use the frequencies of different numbers in a list. First I tried calculating it with a dictionary but I got TLE ...
User's user avatar
  • 23
-1 votes
1 answer
52 views

I was reading a bit on DS/A and found this cheat sheet on Leet Code.. Add or remove element from arbitrary index: O(n) Access or modify element at arbitrary index: O(1) Intuitively I would think they ...
rarara's user avatar
  • 301
0 votes
0 answers
71 views

I'm trying to analyze the time complexity of the following recurrence relation using the recurrence tree method: T(n) = T(n - sqrt(n)) + n^2 The challenge I'm facing is determining the height of the ...
pouya's user avatar
  • 1
6 votes
1 answer
115 views

I'm working with multiple ordered lists, each containing tuples of the form (key, value), where each list is sorted in ascending order by key. I want to merge these lists into a single ordered list ...
Isak's user avatar
  • 95
1 vote
1 answer
107 views

I am trying to solve the "Kth Largest Element in an Array" problem on LeetCode. I have two different approaches that both theoretically have the same time complexity (O(n) on average), but ...
459zyt's user avatar
  • 115
0 votes
3 answers
148 views

Task of the problem: Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more ...
D.S.Dudhia's user avatar
0 votes
1 answer
64 views

I know this is a simple question, but I'm thrown off by some additions related to linear algebra problems being treated as constant time vs. linear time. In this case, I'm interested in summing m ...
Ari's user avatar
  • 103
3 votes
3 answers
195 views

I need to write a python script that counts the number of times these operations: +, -, *, //, %, >, <, ==, <=, >= are performed in a piece of python code relative to the input of N. ...
Geddez's user avatar
  • 51
-3 votes
1 answer
106 views

I was going through few leetcode problems and came across the Anagram Problem. The time complexity for the solution below was mentioned as O(n+m). We are looking at the length of both strings which ...
Nabeel GM's user avatar
0 votes
0 answers
45 views

I'm new to recommender system and I'm currently building a collaborative filtering based recommender system. In my dataset there are current 600 users and 9000 items having different ratings. I have ...
Partha Pratim Sarma's user avatar
2 votes
1 answer
120 views

def f(n):    if n <= 1:        return 1    return f(n-1) + f(n//2) here n//2 is n divided by two truncated towards zero, so 3//2 is 1. I've got this problem in my algorithms class. From my ...
Pecan_'s user avatar
  • 37
0 votes
3 answers
110 views

newtype Prob a = Prob { getProb :: [(a,Rational)] } deriving (Show,Eq,Functor) flatten :: Prob (Prob a) -> Prob a flatten (Prob xs) = Prob $ concat $ map multAll xs where multAll (Prob innerxs,...
Ashok Kimmel's user avatar
1 vote
1 answer
101 views

Problem Statement I am trying to solve a variation of the Maximum Path Sum in a Binary Tree problem where some nodes in the tree are colored red. The path sum is only valid if: The path starts and ...
PodGen4's user avatar
  • 394
-4 votes
2 answers
90 views

I want to compare the effect of multiprocessing for bubble sort. Let us consider first the original one without multiprocessing: import multiprocessing import random import time import numpy as np ...
dato datuashvili's user avatar
0 votes
0 answers
46 views

I am trying to estimate the time complexity of an FEM simulation, that solves the normal contact between a biphasic block and an rigid indenter. Say the block has a mesh with N x N x M nodes and the ...
Peter Uwson's user avatar
1 vote
1 answer
128 views

The following problem was asked during an interview: Given an array of integers as input, the size of an array is n. Perform the below steps in a loop until the first n-1 items in the list are ...
CodeCrusader's user avatar
7 votes
1 answer
130 views

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|...
Cryptic's user avatar
  • 73
3 votes
3 answers
434 views

I have an array of size n, array[i] represents the count of items of a particular type, where i is in range 0 to n-1. I want to pack the items in groups following below rules: All items in a group ...
CodeCrusader's user avatar
1 vote
1 answer
158 views

I have a list of tasks of size n and the time taken to process is represented as tasks[i], where i is index for the task. Processing Step: These tasks should be processed sequentially from i = 0 to i =...
CodeCrusader's user avatar
7 votes
6 answers
448 views

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 ...
Nature9376's user avatar
-2 votes
1 answer
141 views

I am having a hard time understanding the time complexity for the solution to the following LeetCode problem 329. Longest Increasing Path in a Matrix: Given an m x n integers matrix, return the ...
bourne's user avatar
  • 1,259
2 votes
2 answers
96 views

I'm brushing up on my Big O notation via 'Cracking the Code Interview', 6th Ed., and in the chapter on Big O notation, he poses in example 8 that comparison sorts are generally O(n*log(n)). I wished ...
Ythene's user avatar
  • 23
2 votes
1 answer
158 views

It is a famous question which asked about finding longest nondecreasing subsequence from a given array. The question is well studied and have O(n log n) time complexity solutions. I have encountered a ...
tsh's user avatar
  • 4,838
2 votes
1 answer
109 views

I’m given two string arrays, words1 and words2. A string b is a subset of string a if all characters in b appear in a with at least the same frequency. I need to find all strings in words1 that are ...
Nyctophilic Enigma's user avatar
0 votes
1 answer
128 views

class Solution: def countPrefixSuffixPairs(self, words: List[str]) -> int: n = len(words) count = 0 for i in range(n): for j in range(i+1, n): ...
Nyctophilic Enigma's user avatar

1
2 3 4 5
207