# 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.

343 questions
Filter by
Sorted by
Tagged with
44 views

### Find the maximum GCD of a number with respect to all the values in an array for competitive programming

Here is the Question. Find the largest GCD of the input variable with the values of an array. Inputs are as follows:- First-line contains two integers, N and Q. Second-line contains N integers which ...
7k views

### PermCheck Codility with time complexity of O(N)

I have this solution for Codility's PermCheck problem. In summary, the task is to check whether array A contains each number in $1 \ldots N$ exactly once. I got ...
86 views

### Searching an element in a 2D sorted array

I had to write a code (as an exercise) that receives a 2D row wise and col wise sorted array and an element, and return true is the element exists in the array. The first thing that came to mind when ...
60 views

Code Problem ...
5k views

### URLify a string using Python

I have been working my way through the exercises in the book Cracking the Coding Interview. I wanted to get feedback for the following exercise. Write a method to replace all spaces in a string ...
20 views

### Intersection of Two Arrays - Space Time And Complexity [closed]

The problem is as follows: Given two arrays, write a function to compute their intersection. The below code is my solution.I'm just curious as to what the space time and complexity of below algorithm ...
80 views

### Permutation 1…N. Answer queries “How many numbers between [X,Y] position are in the interval [L,K]”?

So I am solving this task: We have an permutation of the numbers 1..n. I need to answer m queries: -How many numbers between X-th and Y-th position are in the interval [L,K] (<=k and >= L)? So my ...
57 views

### Choosing between 2 Fibonacci alternatives [closed]

Task: Return the fibonacci value at a given index. e.g: input: 6, return: 8. Algorithm 1: ...
57 views

### Algorithm to find the Array Balance Point

Task: Find the balance point of an array; return the index that if you break the array into left and right at that point will ...
16 views

### Simplifying code for deleting directories

Background info: An FSObject is a dir or a file. The structure definition for a directory (dir) is the following (define-struct dir (name owner contents)). A ...
278 views

### Finding unpaired number in an odd length Array of integers

codility OddOccurrencesInArray: A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element ...
41 views

96 views

### Create custom Queue class with O(1) Enqueue and O(1) Dequeue [closed]

I am implementing a Queue class in C# using a Node/LinkedList class that I also implemented, and I wonder if there is a way to implement the enqueue and the dequeue methods, both in algorithmic ...
69 views

### Time and space complexity of base conversion code

I have an algorithm that performs the base conversion. The input is a string and two ints b1 and b2. The string represents an int in base b1 and converts it into base in b2. My code is: ...
99 views

### Min Heap Priority Queue

This was a part of one an assignment I found online and tried to solve it myself. The objective was to implement a Priority Queue using Min Heap and use Array as the underlying data structure to ...
159 views

### Reverse String in Java

I've been revamping on my coding puzzles practices. What is the complexity (both time and space) for this method? ...
115 views

### Find the first missing positive integer in an array of integers

The problem is the one explained in Given an unsorted integer array, find the first missing positive integer Given an unsorted integer array, find the first missing positive integer. For ...
209 views

Linked List Implementation in Swift Swift 5.0, Xcode 10.3 I have written an implementation for a doubly linked list in Swift. As well, I decided to make the node class private and thus hidden to the ...
195 views

Challenge https://leetcode.com/explore/interview/card/top-interview-questions-easy/93/linked-list/773/ Given a linked list, determine if it has a cycle in it. To represent a cycle in the ...
389 views

### Python Implementation: Summer of 69

SUMMER OF '69: Return the sum of the numbers in the array, except ignore sections of numbers starting with a 6 and extending to the next 9 (every 6 will be followed by at least one 9). Return 0 ...
60 views

### Challenge - Construct binary tree from array [closed]

A coding challenge to construct a binary tree from an array. ...
1k views

### Award Budget Cuts implementation in Java

PRAMP Award Budget Cuts The awards committee of your alma mater (i.e. your college/university) asked for your assistance with a budget allocation problem they’re facing. Originally, the committee ...
359 views

### Seating Students (partitioning sort of)

The goal of this code is to seat students in a classroom based on a single test score. We want students to be evenly distributed across the class such that every student is positioned next to the ...
133 views

### Modeling, view and projection transformation using vector and point in homogenous form

I know this is horrible code. This program is for performing modeling, view and projection transformation. The program reads input from scene.txt and outputs the <...
61 views

### Find the number of all specific substrings in a string

I would like to ask a code review regarding a concrete exercise. Let's suppose I have to get the number of all specific substrings in a string. We call something specific if any of these conditions ...
92 views

### Kruskal MST algorithm

I came up with the following code by following Prof. Sedgewick's lecture on Coursera. Please review this code and let me know if there is anything that I got wrong in implementing Kruskal's ...
4k views

### Check if a string is a permutation of a palindrome using Python

This is a solution to exercise 1.4 from Cracking the Coding Interview written using Python 3. Given a string, write a function to check if it is a permutation of a palindrome. Example: 'Tact Coa' ...
93 views

### LeetCode: Best Time to Buy and Sell Stock II

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ Please review for performance. Say you have an array for which the i-th element is the price of a given stock on day i. ...
228 views

### Rotate matrix clockWise and counter clockWise

This code is a mix of the same question one time rotating to the right and one time to the left. I tried to simplify the code since I'm struggling with all of the indexing here. https://leetcode.com/...
82 views

### Coding Challenge: Return The Smaller String

A coding challenge in which we are to write a function that compares two strings and returns the one that is smaller. The comparison is both lexicographical and numerical, depending on the content of ...
124 views

### Frog Jump time complexity

I have tried to work out the Frog Jump task on Codility. The algorithm for solving this is rather simple but the maximum score I am able to achieve is 55% (also 44% with modulus operations). A ...
I have two lists of numbers: $$\{i_1, i_2, i_3,i_4\}$$ and $$\{j_1,j_2,j_3,j_4\}$$ The problem I want to solve is: Inside a loop, if the following two conditions are satisfied, then it will do ...