Skip to main content

Questions tagged [complexity]

Complexity is the analysis of how the time and space requirements of an algorithm vary according to the size of the input. Use this tag for reviews where the "Big O" is a concern.

Filter by
Sorted by
Tagged with
5 votes
1 answer
363 views

Background I can't seem to find an existing answer solving this doubt of mine. In academic books, it seems that DFS is usually presented in both recursive and iterative forms. The implementations ...
Michel H's user avatar
  • 151
7 votes
3 answers
1k views

I am a C++ programmer trying to learn C. Please critique my C code here. I am trying to make a small "hash table" that's \$O(n)\$ lookup. But, it is stack-based and so should be no slower ...
ijklr's user avatar
  • 397
5 votes
4 answers
558 views

Given an input string contains letters from 'a' to 'g' Count how many substrings are there in the input string such that frequency of any character inside the substring is not more than the number of ...
CodeCrusader's user avatar
12 votes
5 answers
2k views

I want to solve a problem in less time complexity. Here are the details: Given an n*m matrix, n rows and m columns. Initially, the matrix is empty filled with 0s. ...
CodeCrusader's user avatar
7 votes
4 answers
552 views

I developed a heap sort variant that sorts a heap through traversal. Unlike in the standard heap sort, the algorithm does not remove the min element from the heap instead it traverses all the nodes of ...
ariko stephen's user avatar
2 votes
2 answers
437 views

Problem Statement (Source: Leetcode Problem 4: Median of Two Sorted Arrays [Hard])(Topics: [Array] [Binary Search] [Divide and Conquer]) Given two sorted arrays ...
CrSb0001's user avatar
  • 619
2 votes
2 answers
271 views

I'm working on a C# project and have a bloater method ValidateBusinessRules that checks a series of business rules for validating the operations. The current code ...
Pranav Bilurkar's user avatar
2 votes
2 answers
94 views

I've been working on the classic LFU (Least Frequently Used) cache running in O(1) time problem lately and, as a student, I kind of struggled with the algorithms I found online. I got most of the idea ...
NicolaM94's user avatar
5 votes
1 answer
396 views

I'm trying to first formulate this challenge. In short, we want to sum up an stream of random numbers with the following objective: The objective is "simply" to sum up as many sequences as ...
Aicody's user avatar
  • 244
2 votes
1 answer
276 views

I was doing the Hackerrank "New Year chaos" problem. Here is the description: It is New Year's Day and people are in line for the Wonderland rollercoaster ride. Each person wears a sticker ...
user12138762's user avatar
5 votes
2 answers
857 views

I came across this question which asks to create a function which will return true/false based on the passed array containing all the letters to make up the passed word. Each letter from array can ...
user282070's user avatar
7 votes
1 answer
307 views

Given a graph \$G(V, E)\$ with vertices \$V\$ and edges \$E\$, where each vertex is associated with a single color from a set of colors \$C=\{1, 2, ..., k\}\$, we define the following problem: Problem ...
FluidMechanics Potential Flows's user avatar
4 votes
1 answer
169 views

This question is from the PCTC 2022 R2 Past Paper and is a follow-up on my previous question. Previous question I have implemented several solutions suggested, such as creating an array with pages ...
helielicopter123's user avatar
6 votes
4 answers
630 views

While practicing for a school coding challenge, I came across this problem. My code got the right answers but exceeded the time limited. Any tips for how to reduce the time complexity? https://pctc....
helielicopter123's user avatar
4 votes
3 answers
728 views

The problem is: Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] where ...
Oliver's user avatar
  • 41
3 votes
1 answer
155 views

Implementation to progressively draw symbols, when provided with symbol implementations it supports any type of symbols, though for the review purpose just two hand written latin symbols are supported ...
user avatar
-2 votes
2 answers
121 views

I'm trying to reduce the complexity of this piece of code following a SonarQube error. I have several similar blocks, and even if I try to extract them into private methods, the Sonar error persists. ...
goujon's user avatar
  • 11
3 votes
2 answers
601 views

I'm trying to solve the below question: A string of characters X (all in lowercase) of length n is present. We can ask a query <...
driver's user avatar
  • 222
1 vote
1 answer
144 views

I have written code as below: ...
Szyszka947's user avatar
3 votes
2 answers
142 views

I wrote this code to find kth smallest element in the array by renowned algorithm quickselect. Here is the link where you can see the working code. What points are there to be improved? Could you ...
Soner from The Ottoman Empire's user avatar
1 vote
1 answer
405 views

I read data from Excel into a Pandas DataFrame, so that every column represents a different variable, and every row represents a different sample. I made the function below to identify potential ...
Pimsel's user avatar
  • 25
2 votes
2 answers
131 views

A school's task: There are two sequences n_tab and m_tab. For every element m in m_tab ...
Szyszka947's user avatar
2 votes
1 answer
256 views

I'm writing (or at least trying to write) a chess engine in C++. This is the first time I write code in C++, and I use this project to practice. Anyway, I'm following the general guidelines of a ...
BarAmber's user avatar
  • 105
2 votes
1 answer
3k views

I found the two related questions but they, however, do not answer my question: interval map implementation Where exactly does my code not adhere to the specification of the key and value type? The ...
asm's user avatar
  • 121
6 votes
1 answer
516 views

As an exercise I've implemented malloc and free in Python as a first fit free list as described here. This tracks which blocks are free in a doubly linked list that is sorted by the address of the ...
Xander Dunn's user avatar
2 votes
1 answer
86 views

The majority of merge sort implementations searched online are provided with unnecessary variables and code lines. Here is an attempt to reduce that. However, does passing back the subArray as return ...
Thomas Mathew's user avatar
0 votes
2 answers
304 views

def search(nums, target): for i in range(len(nums)): if nums[i] == target: return i if nums[i] == None: return -1 I think ...
111's user avatar
  • 53
-2 votes
1 answer
419 views

I wrote a number plate generation program. The program generates number plates for a car registered with a specific Memory Tag and on a specific date. Number plates use the following format: (2 letter ...
kmvfkmfv's user avatar
3 votes
2 answers
467 views

This algorithm adds two numbers digit by digit using their string representations. I am wondering what the time and space complexities of the following algorithm are. In particular, I am wondering ...
MadPhysicist's user avatar
1 vote
2 answers
1k views

I was working on Jump Game problem on leetcode Question You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your ...
D_S_X's user avatar
  • 189
1 vote
1 answer
414 views

I was trying to to print all subarrays of an array in quadratic time. Here is my code: ...
Vaibhav Vishal Singh's user avatar
1 vote
1 answer
120 views

I have an algorithm that calculates the maximum value of an expression that is made from numbers and * or + by adding parentheses. It has 3 nested loops, so the time complexity should be N^3 ...
Tomas's user avatar
  • 11
1 vote
2 answers
494 views

This is my PHP algorithm for the twoSum problem in leetCode: ...
Chubby Cows's user avatar
0 votes
1 answer
137 views

Note: I'm aware of this existing post which is similar. However, it does not address all my questions sufficiently. I have the following three functions, all of which do the same thing: reverse a ...
Richard Robinson's user avatar
3 votes
1 answer
580 views

As part of an online programming challenge, I wrote a program that implements a stack of integers, supporting adding and removing elements, finding the last inserted element, and the minimum element. ...
gparyani's user avatar
  • 131
1 vote
2 answers
441 views

I need a better implementation than the below code (O(N) Solution), I am grouping countries by language ( data ) is the countries JSON, each country could have 0, 1 .. or more language as the object ...
Odeh Abuzaid's user avatar
0 votes
2 answers
1k views

I'm learning C++, and would like some guidance. I'm pretty sure I'm doing something wrong. This algorithm runs in O(n) time and uses O(n) external space. Could I make a more efficient algorithm for ...
Asher I's user avatar
  • 13
4 votes
1 answer
221 views

I work at a major Swedish insurance company. I'm in charge of a service that matches bank payments with invoices. I will not show the details of that match logic. But one outcome of the match is that ...
Anders's user avatar
  • 690
2 votes
2 answers
319 views

I wrote the below as a solution to: Problem Find the highest product of three numbers in a list Constraints Is the input a list of integers? Yes Can we get negative inputs? Yes Can there be ...
msm1089's user avatar
  • 197
1 vote
2 answers
344 views

Sum of 2 numbers, represented with linked lists, where digits are in backward order or forward order. Backward order Example INPUT:(7->1->6) + (5->9->2) = 617+295 OUTPUT: 2->1->9 = ...
Uomolepre's user avatar
0 votes
2 answers
340 views

I have a method where I fetch user input, check if certain values exist, and based on that build my own custom input object that I would use to search in a database. The code for the search method is ...
AnOldSoul's user avatar
  • 121
3 votes
1 answer
279 views

I have written a function that takes as input a list of 5 numbers, then the program's goal is to return the largest drop in the list. It is important to understand that [5, 3, ...] is a decrease of 2 ...
yungCalculator's user avatar
1 vote
3 answers
247 views

My question arises from this post on MSE where I have provided an answer to solve the question : There are multiple lists given. The number of lists is arbitrary. Each list contains numbers and is ...
Tortar's user avatar
  • 121
1 vote
2 answers
1k views

I have written a code to replace all spaces in a String with %20. ...
salazarin's user avatar
  • 113
2 votes
2 answers
481 views

My C++ solution for HackerRank's "Making Candies" problem, reproduced below, is as optimized as I can make it and appears similar to what others say are optimal solutions. However, six of ...
Ray Hamel's user avatar
  • 298
3 votes
1 answer
148 views

I am trying to make an algorithm that will find the index of a given substring (which I have labeled pattern) in a given String (...
qwerty's user avatar
  • 361
2 votes
2 answers
195 views

The question is: To select 2 numbers out of n positive integer inputs (order matters), where the number that is placed anywhere before the second must be greater than the second by a given number m. ...
Curious student's user avatar
2 votes
0 answers
130 views

I tried following the official solution of LC975 (https://leetcode.com/problems/odd-even-jump/), using a monotonic stack - i.e., I reimplemented their solution (Approach 1) from python in C++. TLDR ...
Mircea's user avatar
  • 322
3 votes
4 answers
229 views

Is this an efficient way to get the largest prime factor of a given number? Other solutions I found involved nested algorithms. ...
Tharindu's user avatar
  • 143

1
2 3 4 5
9