Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
326 views

I wrote a solution to the problem linked below but I'm not sure about its time complexity. I was thinking it was quadratic but it passed within 0 ms when I submitted, so it might be linear idk. I ...
renanmatulianes's user avatar
-1 votes
1 answer
243 views

I read a little bit everywhere that the "in" operator have a time complexity of O(n), yet I used it in a code and idk why but it's acting as if it have the time complexity O(1) So I was ...
Erray's user avatar
  • 11
-4 votes
1 answer
292 views

for (int i = 0; i < n^2; i++) { for (int j = 1; j < i; j = 2j) { for (int k = 0; k < j; k++) { System.out.println("x"); } } } My thoughts are that the outer loop ...
impossibru's user avatar
0 votes
1 answer
132 views

Find distinct triplet (i,j,k) such that i<j<k and sum of the arr[i]+arr[j]+arr[k] is divisible by d? If arr = [3, 3, 4, 7, 8] and d = 5 it should give count as 3 triplet with indices (1,2,3) 3+...
Athul Raju's user avatar
1 vote
1 answer
122 views

I'm implementing a few custom enumerators for my data model, e.g. struct Land { // … let council: Council let size: Int } extension Collection<MyModel> { func lands(in council: Council, ...
Heuristic's user avatar
  • 5,401
0 votes
1 answer
115 views

For my code which is an implementation of the quick find algorithm i generally consider my code for understanding theoretical questions #include <stdio.h> #define N 10000 main() { int i, t,...
Bitwoded S.Demissie's user avatar
5 votes
1 answer
282 views

I've come across the notation recently am confused by what I see. My previous understanding is that big O is supposed to be used to denote an upper bound whereas lower or tight bound uses different ...
Daniel's user avatar
  • 53
0 votes
2 answers
141 views

if(obj.getAttribute() != null) { newobject.setAttribute(obj.getAttribute()); } if(obj.getAttribute() != null) { newobject.setAttribute(obj.getAttribute()); } if(obj.getAttribute() != ...
Robert's user avatar
  • 82
-2 votes
1 answer
416 views

I am looking for a function or gem that gives me the cyclomatic complexity of a function. For example, using rubocop, If I write def my_func(foo) foo.details['errors'].each do |attr, message| ...
Constantin De La Roche's user avatar
-1 votes
1 answer
130 views

Code: #include <iostream> #include <vector> template<typename T> std::vector<T> flatten(std::vector<std::vector<T>> const &vec) { std::vector<T> ...
MWaleed Malik's user avatar
0 votes
0 answers
78 views

I am trying to calculate complexity of a recursion method inside another methos in a simple while loop. I dont know how to asnwer this question, I think To just apply the answer O(N*Y) while Y stands ...
itamar nahum's user avatar
0 votes
1 answer
34 views

I'm getting started with complexity and I wanted to know why the example given below is O(n^2) and not O(n), would you guys help me? I need it fast for an exam. l1 = [] for e in range(0, n): if ...
Ricardo Vilar's user avatar
0 votes
0 answers
88 views

I need some help answering this question : How do I find the complexity of the matrix B and f knowing that I have this code : d = 123456; randn('state',d); rand('state',d); n = 1000; A = diag(1+rand(...
Rustless's user avatar
1 vote
0 answers
76 views

I added the getCValue method to reduce the cyclomatic complexity, but the cyclomatic complexity still persists, how can I reduce it? Can I change this code using Regex, if I can how? Please help me.
stromboli's user avatar
2 votes
2 answers
309 views

Problem Description We have a vector<A> v containing for 4 objects. Each object has the following members x, y, z and w. Two objects are considered equal if the have the same x and y. In that ...
Hani Gotc Reinstate Monica's user avatar
-1 votes
1 answer
162 views

How do you properly calculate Cyclmetric Complexity? According to Wikipedia the cyclometric complexity of the following code: if (c1()) f1(); else f2(); if (c2()) f3(); else f4(); is ...
Ben Carp's user avatar
  • 26.9k
1 vote
1 answer
136 views

I'm learning about time complexity and I understand the gist of it, but there's one thing that's really confusing me, it's about understanding the time complexity of a while loop in a for loop. This ...
Moqm's user avatar
  • 11
0 votes
0 answers
872 views

So, I needed to find all the index of elements from an array whose sum is equal to N. For example : Here I want to find indexes whose sum should be equal to 10. Input : int[] arr = { 2, 3, 0, 5, 7 } ...
Sarfaraz Ansari's user avatar
1 vote
0 answers
48 views

The problem which is on LeetCode says that You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. ...
Hax's user avatar
  • 154
0 votes
2 answers
503 views

I did not understand how this piece of code will generate a complexity of O(log n).how many times the statements inside the loop will work? int a = 0, i = N; while (i > 0) { a += i; i /= 2; ...
Arjun's user avatar
  • 15
0 votes
0 answers
46 views

Hello I have a binary search function and I want to prove that it has Logarithmic complexity. I have no idea how to prove this and would really use some help Here are my execution times for the ...
antekkalafior's user avatar
0 votes
0 answers
41 views

Hi guys I am practicing my algorithm and complexity theory. I want to know what is the order of complexity of the algorithm developed taking the x-axis as the size of the vector? (Big O notation). ...
Nicolas's user avatar
  • 1,263
0 votes
3 answers
740 views

So I have been studying the complexity of algorithms, but this one I can't uderstand. If I use a global variable to check how many times the function is called it will calculate the number 11 then ...
user avatar
0 votes
0 answers
328 views

For the given problem below, what would be the time complexity of my solution (below the problem). I think it is not O(n^2), but I am not sure if it is O(n). Problem: You are given two strings s and t....
myTest532 myTest532's user avatar
1 vote
0 answers
123 views

I am learning algorithm complexities. So far it has been an interesting ride. There is so much going behind the scenes that I need to understand. I find it difficult to understand complexity in ...
James Parker's user avatar
2 votes
2 answers
161 views

I am trying to learn time complexities. I have come across a problem that is confusing me. I need help to understand this: my_func takes an array input of size n. It runs three for loops. In the third ...
James Parker's user avatar
0 votes
1 answer
168 views

I am currently on 94. Binary Tree Traversal on leetcode and I am not sure how to analyze the run time and space complexity of the question. In my opinion, the time complexity for the question seems to ...
Jialin Zhen's user avatar
0 votes
1 answer
3k views

How can I improve the Cognitive Complexity in my code? I have a method which has while loop and inside that lot of IF ELSE blocks, I tried to remove IF ELSE with SWITCH Statements but no improvement ...
Manas's user avatar
  • 45
0 votes
1 answer
59 views

I am building an application which uses a lot of vectors and for which I am using a lot of third party and system assemblies. The result of this is that I have four ways to to represent 3d double ...
lmcdev's user avatar
  • 3
1 vote
1 answer
210 views

I like the python package radon and use it fairly often to help find/reduce complex code. I'm normally developing in Sublime Text, and running radon beside in console, but would really like to have ...
sur.la.route's user avatar
7 votes
1 answer
380 views

I am trying to integrate lizard to track the code complexity of an android app on sonarqube. The command used to get the complexity report from lizard is: lizard src/main -x"./test/*" -x&...
Gurunath Sripad's user avatar
1 vote
1 answer
215 views

I was trying to make a recursive realtime simulation to see it it was possible within the simpy framework. the function was made to track into a log dictionary... The jupyter kernel stopped working ...
AbhiCoder's user avatar
0 votes
1 answer
618 views

Is there a way to remove this if else block inside snackbar by replacing it with lambda or infix or anything to make it without +2 nesting in cognitive complexity else { snackBarBuilder( ...
hodokeg's user avatar
  • 19
2 votes
2 answers
593 views

I have an method to convert roman numbers to common decimal. I used here an one for cycle and a lot of "if" conditions. SonarLint in my IDE says me that Cognitive Complexity of this method ...
nc_6d's user avatar
  • 25
0 votes
1 answer
151 views

I'm studying the complexity of functions in python, and I have this two there Im not sure, one because I think it's infinite loop and second is the not in method build in on python: 1- The function f1 ...
António Rocha Gonçalves's user avatar
0 votes
0 answers
113 views

I had the next problem: Given an array, count the number of segments of length k in which this happens; the number of positives in the left-half of the segment is bigger or equal to the right-half. As ...
Theo Deep's user avatar
  • 786
0 votes
0 answers
27 views

F(i, j) represents the maximum value the user can collect from i'th coin to j'th coin. F(i, j) = Max(Vi + min(F(i+2, j), F(i+1, j-1) ), Vj + min(F(i+1, j-1), F(i, j-2) )) As user wants ...
Rohit Kashyap's user avatar
-3 votes
1 answer
373 views

n is a number between 1 and +infinity and this is to know the complexity of an algorithm I need to see if n^log(n) is bigger than n!
Hi world's user avatar
1 vote
0 answers
226 views

when creating a BitArray and initializing all of its value to 0 (via constructor, new BitArray(size, false);) what is the time complexity of such operation? It's not in the docs about collections. ...
Aviv Vetaro's user avatar
1 vote
1 answer
69 views

I did this as a solution to one of the leetcode problems, but I'm not sure what the complexity of my algorithm is. public String countAndSay(int n) { if (n == 1) return "1"; ...
User2345's user avatar
0 votes
1 answer
155 views

If you had an algorithm with a loop that executed n steps the first time through, then n − 2 the second time, n − 4 the next time, and kept repeating until the last time through the loop it executed 2 ...
Manuel Hernandez's user avatar
1 vote
1 answer
258 views

Leetcode 78 question potential solution: class Solution(object): def __init__(self): self.map = {} def helper(self, count, nums, vals, result): if count == ...
Jake's user avatar
  • 17k
0 votes
1 answer
390 views

I have algorithm such as: for(int i=1; i<=n; i++) for(int j=1; j<=2*n; j=j+2) for(int k=i; k<=j; k++) instr; I need to find a formula that will determine how many times the &...
Patryk Wojcieszak's user avatar
0 votes
1 answer
390 views

I am trying to solve the following problem: Given a beginWord, say pig, and an endWord, say phi, and a list of words wordList, say [phg, phi]. We are allowed to change one character of beginword each ...
penny's user avatar
  • 215
1 vote
2 answers
778 views

function recursion(n){ if n==0 return for(let i=0; i < n;i++){ for(let j=0; j< n; j++){ console.log('*'); } } recursion(n-1); } recursion(100); What is ...
user9312404's user avatar
0 votes
1 answer
365 views

So i have an array which has even and odds numbers in it. I have to sort it with odd numbers first and then even numbers. Here is my approach to it: int key,val; int odd = 0; int index = 0; for(int ...
abdullah's user avatar
0 votes
2 answers
397 views

Can someone please help me with the time and space complexity of this code snippet? Please refer to the leetcode question- Word break ii.Given a non-empty string s and a dictionary wordDict containing ...
curiousD's user avatar
0 votes
1 answer
2k views

I know that if I have a function like: public int addOne(int a){ return (a+1) } The time complexity order will be O(1) since we only do one operation (the sum). But what if I have a function that ...
ROBlackSnail's user avatar
1 vote
2 answers
140 views

I'm learning how to find algorithm complexity and I can't figure out what's the complexity of this algorithm. Could someone explain to me how to get the answer? void algorithm(int a, int b) { ...
ItsNotMyFault's user avatar
0 votes
1 answer
58 views

for n in range (1, n): for j in range(1, n+1): k = 1 while k <= j: sumfunc() k *= 42 (Python code, meaning from 1 to n) How would one determine the numbers ...
Hilberto1's user avatar
  • 506