All Questions
Tagged with array programming-challenge
105 questions
3
votes
2
answers
340
views
Given an array, remove zero or more elements to maximize the reduction where you add odd values and subtract even values
Here's a code challenge I got. (I could not solve the challenge, I ran out of time. I rephrased the challenge language and I am trying the challenge again for personal growth & computer science ...
0
votes
1
answer
135
views
Distribute items over array in order to minimize the difference between min and max array values
I came across this problem in a programming challenge a few days ago. I came up with the implementation below, however it resulted in a "time limit exceeded" failure for a few of the test ...
3
votes
1
answer
274
views
Array rotation in C++
I am completely new to data structures and algorithms.
I tried this problem on hackerank. I got the desired output but my code wasn't efficient enough to execute in the given time limit.
How can I ...
10
votes
4
answers
3k
views
First non-repeating Character, with a single loop in Python
I recently tried to solve the first non-repeating character problem. Please tell me if my solution is valid. I'm aiming for O(n) with a single loop.
My thinking is, it would be easy to tell you what ...
2
votes
1
answer
73
views
Molybdenum2019 challenge efficient implementation
I'm working on a solution that is correct but inefficient.
https://app.codility.com/programmers/task/leader_slice_inc/
This is my code :
...
1
vote
1
answer
417
views
Perform various actions on a list
I am solving the following HackerRank problem:
Consider a list (list = []). You can perform the following commands:
insert i e: Insert integer e at position i.
<...
5
votes
1
answer
835
views
Find the shortest sub array that contains all element from 1 to K
I'm trying to solve this problem here. The question is all about finding the shortest sub array inside an array that contains all the element from 1 to K.
Input:
The first line contains three space-...
3
votes
1
answer
263
views
Find the maximum value between minimum values in sub-arrays
I have an array of integers, I have to find all sub-arrays of different size from 1 to len(array). In every sub-array, I have to ...
13
votes
5
answers
2k
views
Array manipulation: add a value to each of the array elements between two given indices
This is a Hackerrank problem: https://www.hackerrank.com/challenges/crush/problem
You are given a list of size \$N\$, initialized with zeroes. You have
to perform \$M\$ operations on the list and ...
6
votes
3
answers
316
views
Largest Triple Products without using sort?
I implemented the Largest Triple Products algorithm, but I use sort which makes my time complexity \$O(n *log(n))\$. Is there a way to implement it without a temporary sorted array?
The problem:
You'...
3
votes
1
answer
111
views
Find lowest consecutive value
I have created a program where I first set the size of the array and
how many times I will look for consecutive values, then I fill in the
array and finally I insert the consecutive values, it should ...
3
votes
2
answers
486
views
Checking if naughts or crosses win in Tic Tac Toe
I am working on a coding challenge for Tic Tac Toe. I am calculating the results and inserting them into the database.
However I have a long and messy if statement, which checks if the array's values ...
2
votes
1
answer
977
views
Count number of previous elements greater than its element at present index
Suppose I have a vector containing n elements. I want to find out the number of previous elements greater than its element at present index i. I want to find ...
4
votes
2
answers
302
views
Maxcounters in JavaScript
I am trying to solve this question: MaxCounters.
Solving it is straightforward, but solving it fast enough is proving very difficult. How can I improve the performance of this code? At the moment it ...
2
votes
1
answer
114
views
Propagation in grid
Can I do it with a lower Big O / better code? How can I improve this solution?
Task:
Let's assume we have a array like this:
1 0 0 1 0
0 0 0 0 0
0 0 0 1 0
0 0 0 0 0
1 0 0 0 0
...