practice-problems | programming interviews with pretty practice problems | AWS library
kandi X-RAY | practice-problems Summary
kandi X-RAY | practice-problems Summary
Prepare for programming interviews with pretty practice problems.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Checks to see if there is enough money .
- Linear search for a node .
- Returns the set of uncoupled integers .
- Reads data from an input stream .
- Determines if this node contains a cycle .
- Get or create a node .
- Calculates the number of solutions of a given amount .
- Recursively count coins in a given array of coincounts .
- converts a comma - separated string to an integer array
- Find all non - null integers in an array .
practice-problems Key Features
practice-problems Examples and Code Snippets
void merge(int[] Arr, int start, int mid, int end) {
// create a temp array
int[] temp = new int[end - start + 1];
// crawlers for both intervals and for temp
int i = start, j = mid + 1, k = 0;
// traverse b
public int solution(int[] A) {
double minAvg = Integer.MAX_VALUE;
int index = 0;
if (A.length <= 2) {
return 0;
}
for (int i = 0; i < A.length - 2; i++) {
if ((A[i] + A[i + 1]) /
public double findMedianSortedArraysNoob(int[] nums1, int[] nums2) {
int m = nums1.length;
int n = nums2.length;
double result = 0.0;
int[] resultArr = new int[m + n];
for (int i = 0; i < m; i++) {
Community Discussions
Trending Discussions on practice-problems
QUESTION
I am new to combinatorics problems and trying to understand how to solve this problem, I understand that nC2 is finding the numbers where order matters, but after that I have no idea how to proceed further in the math problem. Please explain further, no code needed. https://www.hackerearth.com/practice/math/combinatorics/inclusion-exclusion/practice-problems/algorithm/aryan-and-consulting-sessions-0e0656ab/
...ANSWER
Answered 2022-Mar-11 at 04:02Let students are graph vertices, possible pairs are edges. This graph is complete K_n
, number of edges is p = n*(n-1)/2
(nC2 as you wrote)
We need to find number of edge covers for this graph.
I wanted to count numbers of edge covers containing from (p+1)/2
to p
edges, but seems values are too big and this is rather complex problem.
But we can find formula for counting overall quantity of edge covers for complete graph K_n
here in OEIS
QUESTION
I am trying to solve a question where I am supposed to print the max number of a particular symbol that repeats continuously but I have to give inputs manually for each individual row. If I copy and paste the test cases it returns an error. Below is the full code and testcase with outputs given after.
NOTE: if not fully understood the problem please visit https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/maximum-border-9767e14c/
...ANSWER
Answered 2022-Mar-05 at 11:27Try This:
QUESTION
This is a very simple program where the user inputs (x,y) coordinates and distance 'd' and the program has to find out the number of unrepeated coordinates from (x,y) to (x+d,y).
For eg: if input for one test case is: 4,9,2
then the unrepeated coordinates are (4,9),(5,9) and (6,9)(x=4,y=9,d=2). I have used a sorting algorithm as mentioned in the question (to keep track of multiple occurrences) however the program shows runtime error for test cases beyond 30. Is there any mistake in the code or is it an issue with my compiler?
For a detailed explanation of question: https://www.hackerearth.com/practice/algorithms/sorting/merge-sort/practice-problems/algorithm/missing-soldiers-december-easy-easy/
...ANSWER
Answered 2022-Feb-26 at 09:03The problem was the bounds of the array int x[1000]
is not enough for the data given below.
QUESTION
How do i correctly solve this question Benny and Segments. The solution given for this question is not correct . According to editorial for this question, following is a correct solution.
...ANSWER
Answered 2021-Sep-08 at 06:35As your test-case demonstrates, the error is that when adding new segments to extend the current segment, there's no test to check whether the new segment can reach the current segment or would leave a gap. To do so, compare the new segment's left end to your current segment's right end:
QUESTION
I was trying to solve the problem Modulo strength at hackerearth ,
https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/golf/modulo-strength-4/ ,
so basically we have to find all such pairs of no. (say i,j) such that A[i]%k=A[j]%k where k is a no. given in the question ,
i tried brute force approach and got time limit exceeded at some of the last test cases and
in the discussion tab i found a code which is working but i couldn't understand what exactly it does, and the underlying thinking behind the algorithm used.
ANSWER
Answered 2021-May-18 at 06:18Let's first go through with the purpose of every variable in the code.
The purpose of n,k,s
is explicitly given.
a[n]
is for reading the numbers in array.
std::vectorv(k,0)
stores k sized vector of 0's, and v[i]
indicates the number of variables in a[n]
for which a[j]%k==i
.
In the last loop, the following has done. The number of pairs that can be constructed with n
elements is n*(n-1)
(basic combinatorics), and if we have v[i]
numbers for which the condition is satisfied and a[j]%k==i
the number of pairs that can be constructed is v[i]*(v[i]-1)
. The loop sums up the number of pairs for every remnant i
.
QUESTION
Why is break
used here to break out of if statement? Is it allowed?
And why are x and y made 0 at the end? x = 0; y = 0
ANSWER
Answered 2021-Feb-09 at 09:44break
doesn't exit the if statement, it exits the inner-most loop. it is most certainly allowed, break is only useful inside an if
or switch
statement.
x and y need to be reset to zero every time the outermost 'q' loop runs. A clearer way to organize the code would have been to put each local variables inside its smallest possible scope, and name the variables appropriately to help readability. i.e. x
=>n_upper_vowels
,y
=>n_lower_vowels
etc.
QUESTION
I’m writing a Django web app which basically presents the web visitor with the option to encrypt / decrypt a message using a very rudimentary caesar cipher. I got the encryption function to work but when I tried to implement conditional logic in my template to handle the user’s initial choice on the landing page (the option to encrypt or decrypt), Django is not serving the client the option. I’m not sure why.
I’m expecting Django to give the web visitor this choice on the landing page:
Would you like to encrypt a plaintext message? Or would you like to decrypt a scrambled message?
(...where each question is a hyperlink that takes the visitor to a page to enter their message).
When the web visitor lands on the page, neither option is showing. Django just serves a blank template.
Here is a temporary mirror of my dev server: https://d0d342ea4934.ngrok.io
Here is my views.py:
...ANSWER
Answered 2021-Jan-28 at 23:41As for me all your problem is that you have to run url
with arguments to see anything
QUESTION
I was attempting a problem to check symmetry in logos (link : https://www.hackerearth.com/practice/data-structures/arrays/multi-dimensional/practice-problems/algorithm/roy-and-symmetric-logos-1/description/). This is the function accepting input of the array called logo[][]:
...ANSWER
Answered 2021-Jan-22 at 16:54The trouble is that when I run the code, for N = 2, it takes 4 inputs:
This is expected for N == 2
:
QUESTION
Anybody here who solves problems on HackerEarth? I am confused with the way they supply the input data.
I have been using Leetcode till date to solve problems and I am pretty happy with them but unfortunately some people prefer HackerEarth to host coding challenges and I have issues trying to read the input test case properly.
Take this for example: https://www.hackerearth.com/practice/algorithms/searching/ternary-search/practice-problems/algorithm/small-factorials/submissions/
I did my research and found their "solution guide" which has the wrong info: https://www.hackerearth.com/docs/wiki/developers/solution-guide/
How would I read the individual lines and output the results in JS (Node v10) judge?
Thank you.
...ANSWER
Answered 2020-Oct-11 at 20:42Just logged into and looked it up here.
Seems to be similar to HackerRank which I'm not fond of. (LeetCode's UI is fun and much easier to use.)
On LeetCode, we don't have to print things out, here it seems we have to print the output (for instance in JavaScript we would use
console.log
not to mention printing inside methods is generally a bad practice coding).
This solution (copied from one of those activities) seems to be passing based on which you can figure things out:
QUESTION
While practising DFS problems on HackerEarth using Java, one of the test cases results in NZEC error when checking it out, it displays StackOverFlow error. I checked it many of the times but all of the test cases pass except one which results in an error, and this is not for that specific problem but for many of the problems(DFS problems) one test cases is always there out of 10 or 20 which always result in NZEC when solving with java.
I don't whether it is due to my Adjacency list implementation or something else. Here is the problem one of the problem.
My code:
...ANSWER
Answered 2020-Oct-03 at 20:00No one answer to my question, this question is not from the live contest, it takes me a week to figure out the solution for my problem. The problem of StackOverFlow is due to the limitation of the number of stack calls on HackerEarth IDE and similar online IDE for Java which is 100,000 calls are only allowed, to avoid such, create a thread object and pass stack size as a parameter manually, which will increase the stack size.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install practice-problems
You can use practice-problems like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the practice-problems component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page