Skip to main content

All Questions

Filter by
Sorted by
Tagged with
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 ...
zing's user avatar
  • 203
1 vote
1 answer
404 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. <...
Nestor's user avatar
  • 291
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 ...
jeremy radcliff's user avatar
0 votes
2 answers
741 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\...
Madhuraank B's user avatar
1 vote
2 answers
504 views

Maximum contiguous sum in an array

The following code is my solution for the following Daily Coding Challenge Given an array of numbers, find the maximum sum of any contiguous subarray of the array. For example, given the ...
MrJoe's user avatar
  • 2,053
5 votes
1 answer
6k views

(Codewars) Range Extraction

Kata: https://www.codewars.com/kata/range-extraction/python A format for expressing an ordered list of integers is to use a comma separated list of either individual integers or a range ...
Tobi Alafin's user avatar
  • 1,752
6 votes
7 answers
14k views

Hacker rank 30 days of code Maximum Sum of Hourglass

I came up with this code as a solution to a contest question. The original question can be viewed here for attribution sake: Hackerrank 2d array problem Sample input is like this: ...
ananth vankipuram's user avatar
3 votes
1 answer
157 views

Finding the smartest set from an array of numbers

Is there any way to make this program run in better time ? While running, it is taking 1 second for the sample test case to pass and 5-10 seconds for the rest of the test cases. Problem statement ...
codaholic's user avatar
  • 185
3 votes
2 answers
2k views

Maximum sub-array of non-negative numbers

This is the "Maximum sub-array" problem from CodeChef: Find out the maximum sub-array of non negative numbers from an array. The sub-array should be continuous. That is, a sub-array ...
Latika Agarwal's user avatar
3 votes
2 answers
474 views

2D array inquiries

I am trying to solve a problem as described below: You are given an input of a n*m forest. You have to answer a group of inquiries. Your task is to return the number of trees for every ...
Kurns's user avatar
  • 175
8 votes
1 answer
7k views

Rearrange list by modifying the original list, put even-index values at front

I am relatively new to python and I am still trying to learn the basics of the language. I stumbled upon a question which asks you to rearrange the list by modifying the original. What you are ...
Nauman Shahid's user avatar
1 vote
1 answer
567 views

Find max in-order difference in array

Given an array A of integers, find the maximum of j - i subjected to the constraint of A[i] <= A[j]. If there is no solution possible, return 0. Example : A : [3 5 4 2] Output : 2 for the pair ...
kshikhar's user avatar
  • 121
2 votes
1 answer
6k views

HackerRank: Left Array Rotation in Python

Here is the problem on HackerRank. I want to know how I can improve this code. I am mainly trying to improve the following skills: Documentation, functional programming (top-down approach), accurately ...
Clever Programmer's user avatar
11 votes
3 answers
4k views

Students with second lowest grade

I solved the Nested List Python challenge on HackerRank.com passing all test cases. Although this problem can likely be solved with a short script with clever one-liners, my approach was instead to ...
Phrancis's user avatar
  • 20.4k
7 votes
7 answers
9k views

Python address index +1 with list comprehension

Task from CodingBat: Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after a ...
mcgyver5's user avatar
  • 638