All Questions
Tagged with array complexity
36 questions
1
vote
2
answers
387
views
Median of two sorted arrays in Python
Problem Statement
(Source: Leetcode Problem 4: Median of Two Sorted Arrays [Hard])(Topics: [Array] [Binary Search] [Divide and Conquer])
Given two sorted arrays ...
2
votes
1
answer
211
views
Hackerrank "New Year chaos" solution - permute sequence by swapping adjacent terms
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 ...
3
votes
2
answers
122
views
Quickselect algorithm implementation and its time-complexity
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 ...
2
votes
0
answers
199
views
2D Array Word Search: Complexity and Optimization
🧩 Objective
Determine whether a given word is contained in a 2D Array word search.
🔎 Question
1. What are the time and space complexities of the current algorithm?
Time complexity
Linear: \$O(2(r * ...
3
votes
1
answer
202
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 ...
8
votes
1
answer
206
views
An array with \$O(\log\ n)\$ time complexity for all operations
Does this exist already? It's an array (=variable-size list with integer indices) where add/remove/set and get all take \$O(\log\ n)\$ time.
I couldn't find this anywhere, so I made up the name "Log-...
-2
votes
1
answer
189
views
Challenge - Construct binary tree from array [closed]
A coding challenge to construct a binary tree from an array.
...
3
votes
2
answers
4k
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 ...
3
votes
1
answer
657
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.
...
2
votes
0
answers
51
views
Find target in sorted array pivoted at some unknown point in O(log n)
You are given an array sorted in ascending order which is rotated at
some pivot unknown to you beforehand. Find your target in \$O(log n)\$
which means it should be a binary search. If the value ...
4
votes
1
answer
2k
views
Swift - Finding longest binary gap of a given integer
I recently had the chance to try Codility's algorithm training, and the very first one in the list is finding the longest binary gap of a given integer.
I tried to implement this in Swift, and after ...
3
votes
1
answer
1k
views
Median of two sorted arrays
The task is to find the median of two Arrays. I have an O(n) solution.
Can it be written in a better time complexity?
...
1
vote
1
answer
133
views
Possible letter combinations of a dial pad in linear time using a recursive approach
Time complexity: I walk the initial unzipped array of keys representing the number O(N) backwards. I then do an inner walk of the proceeding array of letters *O(L^2), mapping it to every value in the ...
2
votes
2
answers
2k
views
Determine if Array has an Increasing Sequence
I wrote a function in JavaScript that expects an array of integers (negative or positive) and determines if that array has an increasing sequence.
For the sake of better time performance I made the ...
7
votes
1
answer
1k
views
Intersection of two lists in Python
I am currently working on an algorithm, which involves finding the intersection of two lists. That is, given the following inputs [1,2,2,1],...