All Questions
26 questions
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 :
...
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-...
6
votes
3
answers
384
views
Leetcode - First Unique Character in a String
Given a string, find the first non-repeating character in it and
return its index. If it doesn't exist, return -1.
Examples:
...
3
votes
4
answers
3k
views
Rearranging an array such that positive and negative elements are at alternate positions
We are given an array in which we have equal number of positive and negative elements.
We have to rearrange this array such that all positive and negative elements are at alternate positions and ...
6
votes
2
answers
633
views
Add 1 to an integer represented as an array of digits
Problem Statement
This is another LeetCode question I came across, where I need to add 1 to a number.
The number is represented as an integer array where each index position is a digit and ...
0
votes
2
answers
207
views
Verifying if two numbers are equal using ArrayLists
I have some question about the code below. It works correctly, but:
Is there a better/another way to solve the exercise (as an expert would have done:) or mine it's perfectly done?
Also, I don't see ...
7
votes
3
answers
7k
views
Cyclic Rotation
Can I get feedback on my code?
Problem:
A zero-indexed array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of ...
3
votes
3
answers
7k
views
Java 2d array Hourglass Sums challenge from Hackerrank
This is a java solution to a Hackerrank problem.
I know it's not optimized, can anyone help me to refactor and optimize?
Task:
Calculate the hourglass sum for every hourglass in the 6×6 array, ...
3
votes
1
answer
6k
views
Hackerrank Sparse Arrays Solution in Java
I've just solved this problem and I hope you guys give me any feedback to make my code be better.
Problem: There are N strings. Each string's length is no more than 20 characters. There are also Q ...
8
votes
5
answers
2k
views
Repeatedly partitioning an array equally as far as possible
I solved HackerRank Nikita and the Game. The implementation is correct as program passes all test cases.
Nikita just came up with a new array game. The rules are as follows:
Initially, ...
3
votes
4
answers
5k
views
Circular array rotation Java
I have a solution to the HackerRank Circular Array Rotation challenge. It passes 7 test cases out of 15. The rest of them are getting timed out. I think it's because of the huge data set that has ...
2
votes
1
answer
236
views
LeetCode Rotate Array
I have started learning Java and was trying to solve some easy problems from different websites like HackerRank and leetcode.I am relatively new to programming so please don't mind if this is too ...
5
votes
1
answer
381
views
Project Euler #127 abc-hits
Problem (Rephrased from here):
The radical of \$n\$, \$rad(n)\$, is the product of distinct prime factors of \$n\$. For example, \$504 = 2^3 × 3^2 × 7\$, so \$rad(504) = 2 × 3 × 7 = 42\$.
...
4
votes
2
answers
6k
views
Finding all the subsets in an array of integers that sum to a given target
Problem Statement:
Given an Array if ints, Find out all the subsets in the Array that
sum to a given target value.
Example:
If the input array is:
...
5
votes
1
answer
2k
views
Finding common elements, ignoring duplicates, in two given string arrays
I am going through the CodingBat exercises for Java. Here is the one I have just completed:
Start with two arrays of strings, a and ...