HPE CodeWars 2021 - Practice Arena
Codingal

HPE CodeWars 2021 - Practice Arena

Hosted by Codingal

STARTS AT:

10:00 AM CUT, Mar 12, 2021

ENDS AT:

07:30 AM CUT, Apr 10, 2021

TEAM SIZE:

1 member

LOCATION:

Online

প্রতিযোগিতা শেষ হয়েছে।.

Overview

This is a Practice Arena for HPE CodeWars 2021 India Edition. Students get 30 coding problems to solve. It will be important for students to complete this practice session to be aware of how virtual competitions and problem-solving works. They will also get an idea of what type of problem statements to expect in the main competition.

 

You have time till 1 PM IST on Apr 10, 2021 to practice. You can visit the Practice Arena and solve problems at any time you want. You can submit your programs for a problem as many times as you want.

 

Codingal is hosting the first-ever virtual coding competition HPE CodeWars 2021 India Edition for Grade 9-12 students. The students will need to solve coding problems using any of the following programming languages - C, C++, Java, Python, and JavaScript. Prepare for the competition by practicing. Click on "Start now" and start solving practice problems!

Solution Guide

You can see the Practice Problems and select a problem from there. Then, you need to select the language from tabs and write your code in the editor. You can compile and test your code on sample testcases by clicking on 'Compile & Test'. You can submit your code for judge by clicking on 'Submit'.
You can use this link to check the solutions to all the practice problems.

We will describe solutions for Sum of N in different languages for successful submission.

 

Sum of N 

 

Input:

First-line contains integer N denoting number of elements of the array. The next line contains N integers denoting the elements of Array.

 

Output:

You have to print the sum of all elements in the Array.

 

Solutions in different languages for Sum of N are written below.

 

Python

N = int(input())

arr = list(map(int, input().split()))

sum =0

for i in range(N):
	sum += arr[i]

print(sum)

 

C

#include <stdio.h>

int main() {
    
	int N;
	scanf("%d", &N);

	int arr[N];
	for (int i = 0; i < N; ++i) {
		scanf("%d", &arr[i]);
	}

	int sum = 0;
	for (int i = 0; i < N; ++i) {
		sum += arr[i];
	}

	printf("%d", sum);

    return 0;
}

 

C++

#include <iostream>
using namespace std;

int main() {
    
    int N;
    cin >> N;

    int arr[N];
    for (int i = 0; i < N; ++i) {
      cin >> arr[i];
    }

    int sum = 0;
    for (int i = 0; i < N; ++i) {
      sum += arr[i];
    }

    cout << sum;

    return 0;
}

 

Java

import java.util.Scanner;

// Always use Main class with public main method
class Main {

    public static void main(String args[] ) throws Exception {

        Scanner s = new Scanner(System.in);

        int N = s.nextInt();
 
        int[] numArray = new int[N];        

        int sum = 0;
        for(int i=0; i<N; i++){
            numArray[i] = s.nextInt();
        }

        for (int i = 0; i < N; ++i) {
            sum += numArray[i];
        }

        System.out.print(sum);
        s.close();
    
    }
}

NOTE: Always use Main class with public main method.

 

Javascript

function main(input) {
    
    var input_T = input.split('\n');
    var N = parseInt(input_T[0]);
    var arr = input_T[1].split(' ');

    var sum = 0;

    for (var i = 0; i < N; ++i) {
        sum += parseInt(arr[i])
    }

    console.log(sum);
}
 
process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";
 
process.stdin.on("data", function (input) {
    stdin_input += input;
});
 
process.stdin.on("end", function () {
   main(stdin_input);
});

 

FAQs

1. Is the Practice Arena competition online?

Yes, this competition is 100% online. The students can participate as long as they have access to a computer/laptop and an internet connection.

 

2. How much does it cost to enter into this competition?

There is no registration fee to participate in the competition.

 

3. What type of problems will be part of the competition?

There will be coding problems to solve using C, C++, Java, Python, and JavaScript. Students will be given access to a Practice Arena before the competition. It will consist of 30 coding problems that will help you prepare for the competition.

 

4. How do I prepare for the competition?

We recommend that you solve practice problems in the Practice Arena. This will help you to understand how to participate in the main competition. It comprises detailed information about how programming questions should be attempted and details about the Codingal evaluation system.

 

5. Can I participate in the competition from a mobile?

No. We don't support mobile devices yet for participating in the competition. We suggest you participate in the competition from a laptop/desktop.

 

6. What type of problems will I have to solve in this competition?

All problems in this competition will be coding problems.

  • Write code in the online code editor that is provided with each problem and submit it.
  • You can make multiple submissions. The platform automatically considers the best submission.

 

7. Are the programming problems restricted to specific languages?

The languages that you can write code are mentioned in the challenge details, if applicable.

 

8. What will happen in case there is an issue with my computer or Internet connection?

If there is an issue with your computer or your Internet connection, you will not lose your previously submitted answers. They will be saved on Codingal's servers. You can log in again and continue coding from where you left off. However, the timer will continue running, which is why it is advised that you ensure that your computer/Internet connection is working properly before you begin the challenge.

 

9. How do I Test & Submit my code?

Every problem has the following two buttons:

a. Test

  • When you click Test, the is tested against the sample input and output. You can provide your own custom input too.

  • This ensures that you are able to test your code against predefined sample test cases before you submit your code.

b. Submit

When you click Submit, the code is checked extensively against internal test cases. The following parameters are considered while checking the code:

  • Time limit: The code should run within the stipulated time otherwise, it will throw a Time Limit Exceeded (TLE) error.

  • Memory limit: The code should run within the given memory size otherwise, it will throw a Memory Limit Exceeded (MLE) error.

  • Errors during runtime: Specific test cases check for Runtime Errors (RE) only.

  • Correct answer: If your answer is incorrect, then you will see the message Wrong Answer (WA) on the screen. This means that your program is not printing the correct answer. Ensure that your program conforms with the output format that is required.

 

10. Is it possible to change my submission after I have submitted my code?

Yes, you can edit and submit your code for a problem any number of times before the completion time window closes.

 

11. How does Codingal's evaluation engine determine whether my program is correct?

The Codingal's evaluation engine is an automated code checker for every program and not a human being. The code checker tests your code automatically. Therefore, you must write your code accordingly.

For each problem, based on the specifications mentioned in the problem statement, there will be one or more input files and corresponding (correct) output files. The program that you create is run on each of the input files, and the corresponding output must match the (correct) output files in order.

Your program will be marked incorrect in the following cases:

  • Output files (generated by running your code) do not match the pre-generated output files.

  • Output files (generated by running your code) match all the pre-generated output files; however, it is not in the order in which the pre-generated output files are arranged.

 

12. How does the time limit work?

Your program must read, process, and output the result for all input files within the specified time limit.

The input file will be in the format that is specified in the problem. This means that if each input file contains multiple test cases, then your code must pass all the test cases within the specified time limit.

 

13. How does the total execution time work?

Your code is tested multiple times against different input files. The displayed execution time is the total time spent executing each input file. Hence, Total execution time <= (Time Limit * Number of input files)

Your program is terminated in the following scenarios:

  • If the time that is required to execute each input file exceeds the time limit execution that is set for any input file.

  • If the total time that is required to execute all the input files exceeds the total time limit allowed.

 

14. How does the total memory consumed work?

The total memory consumed by a program is the sum of the memory that is consumed by the program in stack, data, heap, and BSS. To understand more about the address space of a program and the memory consumed, refer to this explanation.

 

15. My program doesn't compile. Why?

  • C/C++

    • Ensure that you are using an updated compiler that complies with the standards.

    • For example, do not use Turbo C++. Code that compiles in Turbo C++ will often not compile on the online judge.

    • Also, remove 'conio.h includes' in your code.

  • Java

    • We support multiple classes and inner static classes.

    • Your code may throw errors if the inner classes are not static.

    • Please note that we will remove this constraint very soon. We will update you when this happens.

  • Other languages

    • The compilation errors that you see on the screen are self-explanatory.

    • However, if you require any more information, please write your query in the comments or send us a chat message.

We recommend you to write code directly in the code editor provided for every problem and not use the local compiler to run your code.

 

16. Does TLE error mean that my code is correct but slow?

No, Time Limit Exceeded or TLE means that your solution has exceeded the amount of time that is allowed for problem execution or for a specific test case. Your solution never finished running in time, and it was stopped in between. There is no definite way to know whether the code was correct.

 

17. What does Wrong Answer (WA) mean?

WA means that your program ran successfully but gave an incorrect answer. This could mean either of the following:

  • Your program contains a bug.

  • You have not interpreted the problem statement correctly.

Apart from the sample input, your code will also be evaluated against multiple input and output cases. Therefore, even if your code passes the sample input correctly, it may not have passed one of the other input and output cases.

 

18. What happens if I indulge in plagiarism?

We take cheating/plagiarism very seriously. You will be disqualified from the competition, and your account may be permanently blocked on Codingal.

 

19. Why is my submission queued?

Your submission is queued because of simultaneous submissions by multiple users. You will receive the result of your submission in real-time as soon as it is processed. Please wait for some time to receive the result of your program.

 

20. My submissions are not evaluated. What should I do?

There may be an issue with the online judge due to which your submissions are not being evaluated. Send an e-mail to support@codingal.com or send a chat message.

 

21. When will I receive the results of the competition?

You can view your ranking on the leaderboard. This leaderboard is updated in real-time and you can see where you stand.

 

22. Where can I view the solutions for the problems of this competition?

Once the competition is over, we will publish the solutions. Keep a watch on this page to view and download all the solutions.

 

23. Why do I see a runtime error when I submit my program?

A runtime error means that the program was compiled successfully, but it crashed or exited with an error. The most common error messages include the following:

 

S. No. Error Description Reason
1 SIGSEGV Segmentation fault error Caused by an out-of-scope array index causing a buffer overflow, an incorrectly initialized pointer, etc.

Signal is generated when a program tries to read or write outside the memory that is allocated for it, or to write memory that can only be read.

For example, you are accessing a[-1] in a language that does not support negative indices for an array.
2 SIGXFSZ Output limit exceeded error Your program has printed too much data to output.
3 SIGFPE Floating point error This usually occurs when you're trying to divide a number by 0, or trying to take the square root of a negative number.
4 SIGABRT Raised by the program This happens when the judge aborts your program in the middle of execution.

This can also be raised due to insufficient memory.
5 NZEC Non-zero exit code error This message means that the program exited to the shell by returning a value that is different from 0.

For languages such as C/C++, this probably means you forgot to add "return 0" at the end of the program.

It could happen if your program threw an exception that was not caught. Trying to allocate too much memory in a vector.

For interpreted languages like Python, NZEC will usually mean that your program either crashed or raised an uncaught exception.

Some of the reasons being in such cases would be: the runtime errors mentioned above. Or, for instance usage of an external library which is causing some error, or not being used by the judge.
6 MLE Memory limit exceeded error This error means that your program tried to allocate memory beyond the memory limit indicated.

This can occur if you declare a very large array, or if a data structure in your program becomes too large.
7 OTHER Generated when you use too much memory Check for arrays that are too large, or other elements that could grow to a size too large to fit in memory.

Sometimes it can also be generated for reasons similar to the SIGSEGV error.

 

Avoiding runtime errors

  • Ensure that you are not using variables that haven't been initialized. These may be set to 0 on your computer but aren't guaranteed to be on the judge.

  • Check every single occurrence of accessing an array element and see if it could possibly be out of bounds.

  • Ensure that you are not declaring too much memory. 64 MB is guaranteed, but having an array of size [100000][100000] will never work.

  • Ensure that you are not declaring too much stack memory. Any large arrays should be declared globally, outside of any functions - putting an array of 100000 ints inside a function probably will not work.

 

Comments

55 comments
Avatar
savithavijay04
I am facing a difficulty. When I press "Compile and Test", my code gets executed successfully with the desired output. But when I select "Submit Code", it fails to execute, and it shows that everything is wrong. I have also tried running the code in my computer and it gets executed successfully with the desired output. So I'm guessing the problem is in your end. Please fix this problem. Thanks.
9
Hide Replies 6
Avatar
dhimaan.s92
Yeah for the third problem of practice arena I'm facin' this problem
Avatar
prateek.sharma
On which problem are you getting the error.
Hide Replies 4
Avatar
vishwa-venkatbavani
I'm getting an error in the practice question : Even or Odd?
Hide Replies 3
Avatar
vishwa-venkatbavani

And error is displayed, on a non existent line! There is no line 16 in my program!
2
Hide Replies 2
Avatar
bhavaygoyal4b
Your code is wrong. Just work a little more on it.
Check line 7
Hide Replies 1
Avatar
vishwa-venkatbavani
I got it, and I changed the typo and made it a string. But what about the error showing up on a line "16"?
Avatar
sohamdokhale1602
I get Internal Error in the Parity Gap 7th Testcase , it's not submitting it... , what should i do ?
2
Hide Replies 3
Avatar
avaneeshk098
You are getting internal error because your code is too slow. On your local machine try to input 1 100000000000 and check if it returns the answer. If not then you might have to change your approach towards the problem. My solution got accepted for this question, it is a good one to understand time complexity and developing different approaches towards a question.
2
Hide Replies 1
Avatar
sohamdokhale1602
oh ok , thank you
Avatar
akashsah2003
Me too my test cases are correct but it is unable to fetch the results. It keeps on loading.
Avatar
vishwa-venkatbavani

I think here's nothing wrong with this code, and even when I compile it, the results are correct. The program correctly returns the opposite of the number. But when I submit it, it says everything is wrong!! It also runs perfectly in my IDE. Something's wrong with the online judge.

By the way, I've gone to the CCC Canadian Computing Competition, and that judge was perfect. No errors.
2
Hide Replies 9
Avatar
vishwa-venkatbavani
Looks like many other people have the same problem as me : Compilation shows it's correct, but after submission it gives a WA verdict for everything. please give me a solution to this!
2
Hide Replies 5
Avatar
prateek.sharma
Now it will work fine
1
Hide Replies 4
Avatar
savithavijay04
Sir my code is compiled and run successfully, but when I submit it, it shows error. Can you please find a solution for this?
Hide Replies 2
Avatar
prateek.sharma
Can you share the problem number and screenshot of the error.
Hide Replies 1
Avatar
savithavijay04
It is happening for every problem. But the code is correct and it is showing the correct output in a normal python interpreter.
1
Avatar
vishwa-venkatbavani
Thank you.
Avatar
technologyscholar03
Yes there is some problem with this editor!
1
Avatar
siddhantattavar12
In the questions where they give you a function and ask you to write the code inside of it, the grader will automatically call the function for you and there is no stdin/stdout work needed. That works for me on most online judges and it worked here too.
Hide Replies 1
Avatar
vishwa-venkatbavani
Oh, alright, nice to know that. Thanks!
1
Avatar
lakshaykumar2193
Whats the java solution to Question 9 in practice arena ?
1
Hide Replies 1
Avatar
prateek.sharma
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

class Main {
    public static void main(String args[] ) throws Exception {
        // Write your code here:
        Scanner s = new Scanner(System.in);
        while (true) {
            double one = s.nextDouble();
            double two = s.nextDouble();
            if (one == 0) break;
            System.out.println(one * two);
        }
    }
}
Avatar
beraamitabh2002
where do i get the solutions of the practice programs in java? I checked the link where it says the solutions for the practice problems are there but i could only find that of python and c++. Please help me out. Thanks.
Avatar
omkar-bajaj-007
Are the solutions to all the problems in the practice arena available anywhere?
Avatar
mandalrahul5681
Did anyone solved the problem 17 (delta inversion) ??
Hide Replies 4
Avatar
avaneeshk098
I have solved problem 17. Let the input array given be 'a' of length n. It is basically to pre calculate the delta inversions as given in the statement and store it in a list 'b' of length n-1, then to create a new array/list 'c' with the first element as the first element of the given array. After that append a[i] + b[i-1] for 1 <= i < n to the new array 'c'. Finally, output the array c.
1
Hide Replies 3
Avatar
sohamshirolkar24
dude, i tried this .Its not working for the test case.
Also, i don't know why they have not shown this last step in their first input on which they show the inversion steps .
I haven't been able to understand what "applying" the delta inversions to the input list means.
can u share ur code here so we can understand what it actually means.
Hide Replies 1
Avatar
avaneeshk098
https://hatebin.com/nkfwtadhum Here you go the link to my code. It was accepted.
Avatar
[deleted]
[deleted]
Avatar
sohamshirolkar24
Are we allowed to test some parts of our code beforehand on our computers ?
For example , during the contest , if I want to make sure a function works but the code is not completely ready, can I test it out on Pycharm or any other IDE I have on my computer?
Hide Replies 1
Avatar
prateek.sharma
Yes you can
Avatar
sohamshirolkar24
I am facing an issue in submitting the solutions. All the codes work when I test them, and the test even say that it has "passed". But when I submit the exact same solution that I tested, I get a WA window.
I am facing this problem in multiple questions.
Please help as this would be a major inconvenience in the actual contest.
Hide Replies 1
Avatar
prateek.sharma
It means that your code is not giving the correct answer on the original tests. You have some logical error. Can you share your code and problem on which you are facing problems.
Avatar
siddhantattavar12
For the 24th problem if there are multiple solutions which one do we print?
My current solution doesn't seem to be working

coins, n = map(int, input().split())

items = []
for i in range(n):
    line = input().split()
    items.append((' '.join(line[:-1]), int(line[-1]), i))

items.sort(key = lambda x: x[1])

flag = items[0][1] > coins

res = [0] * n
for item, price, i in items:
    if coins >= price:
        coins -= price
        res[i] = f'I can afford {item}'
    else:
        res[i] = f'I can\'t afford {item}'

print(*res, sep = '\n')
if flag:
    print('I need more Yen!')
print(coins)
Hide Replies 1
Avatar
prateek.sharma
Please reload the problem statement. There was some error due to which problem statement was not loading fully.
Avatar
siddhantattavar12
I have a few questions about the contest:
  1. I am not able to view the leaderboard. Is it only disabled for the practice contest or will there be no leaderboard for the final competition
  2. I am only able to view the first few submissions. Is there any way to view the remaining submissions
  3. How can I view my final score for each problem
  4. I was able to solve all the problems in Python, but when I tried the same logic in C++, some of the problems gave a WA verdict.
Hide Replies 1
Avatar
prateek.sharma
The leaderboard will be visible in final competition.
Avatar
anbiswasofficial
Thank you for providing the opportunity to practice before the actual competition. I have already opted for few programs in the Practice Session in the Practice Arena but there is a technical problem I guess because the codes which I am writing are not working on the online compiler provided, rather it is showing Could Not Find Or Load Main Class Error. But the codes are working properly on Blue J platform ( I had used Java Programing Language ) and the codes are correct with desired output. I am perplexed what should I do to run them? What am I supposed to do on the Competition day if the problem persists?
Kindly clear my queries. I shall be highly obliged if you look into the matter and help me solve this problem.
Thanking you,
Yours faithfully,
Ankita Biswas
Hide Replies 8
Avatar
prateek.sharma
For what problems are your code giving errors.
Hide Replies 7
Avatar
anbiswasofficial
I have illustrated the error and problem in the Inbox section. Kindly check it Sir.
Thank you
Hide Replies 6
Avatar
anbiswasofficial
Hide Replies 5
Avatar
prateek.sharma
You have to name you class as Main and it should not be public. It should be like this:
Hide Replies 4
Avatar
anbiswasofficial
OK. I'm highly obliged Sir.
Thank you.
Hide Replies 3
Avatar
anbiswasofficial
The first Test output is correct :



The second Test output is correct :



But after submitting, the result is coming wrong :

Hide Replies 2
Avatar
prateek.sharma
In this problem you do not have to ouput "Enter an Integer". You only need to take input and print if it is Even or Odd.
Hide Replies 1
Avatar
anbiswasofficial
OK.
Thank you
Avatar
gulavanichaitrali
I attempted the practice questions but when I compile and check the code it is giving appropriate results but when I submit it is giving error .
what is the reason behind it?
Hide Replies 7
Avatar
prateek.sharma
What kind of error are you getting.
Hide Replies 6
Avatar
gulavanichaitrali
It is giving wrong answers even when the compile tedt is showing correct
Hide Replies 5
Avatar
prateek.sharma
On which problems are you getting wrong answer.
Hide Replies 4
Avatar
gulavanichaitrali
Q2 AND Q3
Hide Replies 3
Avatar
prateek.sharma
In question 2 and 3 you have to simply print the given statment and input. Which language are you using ?
Hide Replies 2
Avatar
gulavanichaitrali
python
1
Hide Replies 1
Avatar
prateek.sharma
In problem 2 you have to do something like this :


In problem 3 you have to do something like this :

Share with your friends

আপনার জন্য প্রস্তাবিত প্রতিযোগিতা

ইভেন্টের ছবি

HPE Codewars Practice Arena

হোস্ট করেছে: Codingal

শেষ হচ্ছেঃ2514 days, 2 hrs, 33 mins

দলের বিবরণঃ১ জন

শ্রেণীঃ8-12
ইভেন্টের ছবি

IOI Algorithms Preparation Guide

হোস্ট করেছে: Codingal

শেষ হচ্ছেঃ405 days, 13 hrs, 33 mins

দলের বিবরণঃ১ জন

শ্রেণীঃ1-12