All Questions
Tagged with programming-challenge array
105
questions
2
votes
2
answers
296
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
120
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
239
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
69
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
401
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
798
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-...
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 ...
3
votes
1
answer
104
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
448
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
943
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
284
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 ...
1
vote
0
answers
97
views
LeetCode: Search a 2D Matrix C#
https://leetcode.com/problems/search-a-2d-matrix/
Write an efficient algorithm that searches for a value in an m x n
matrix. This matrix has the following properties:
Integers in each row ...
2
votes
1
answer
102
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
...
0
votes
2
answers
733
views
Find the maximum value of | Ai - Aj | + | i - j |: [closed]
hackerearth.com practice problem Can you solve it?:
Given an array 'A' consisting of 'n' integers, find the maximum value of the following expression:
\$\lvert A_i - A_j\rvert + \lvert i - j\...