Skip to content

Commit 95343e9

Browse files
UPDATED JAVA README'S
1 parent 3f167fd commit 95343e9

File tree

82 files changed

+4677
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+4677
-166
lines changed

Diff for: .DS_Store

8 KB
Binary file not shown.

Diff for: Java/.DS_Store

6 KB
Binary file not shown.

Diff for: Java/Hackerrank/Can You Access/README.md

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
1-
## **[Can You Access?](https://www.hackerrank.com/challenges/can-you-access)**
2-
You are given a class Solution and an inner class Inner.Private. The main method of class Solution takes an integer as input. The powerof2 in class Inner.Private checks whether a number is a power of . You have to call the method powerof2 of the class Inner.Private from the main method of the class Solution.<br>Constraints<br><br>**Sample Input 0**<br><br>**Sample Output 0**<br><br>
1+
## [Can You Access?](https://www.hackerrank.com/challenges/can-you-access)
2+
3+
![Java](https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white) ![HackerRank](https://img.shields.io/badge/-Hackerrank-2EC866?style=for-the-badge&logo=HackerRank&logoColor=white)
4+
5+
| Difficulty | Max Score | Success Ratio |
6+
|:-----------|:------------:|------------:|
7+
| Medium | 15 | 96.78% |
8+
9+
You are given a class *Solution* and an inner class *Inner.Private*. The main method of class *Solution* takes an integer *[SVG image]* as input. The *powerof2* in class *Inner.Private* checks whether a number is a power of *[SVG image]* . You have to call the method *powerof2* of the class *Inner.Private* from the *main* method of the class *Solution*.
10+
11+
12+
**Constraints**
13+
14+
*[SVG image]*
15+
16+
**Sample Input**
17+
18+
19+
```
20+
8
21+
22+
```
23+
**Sample Output**
24+
25+
26+
```
27+
8 is power of 2
28+
An instance of class: Solution.Inner.Private has been created
29+
30+
```
31+
32+
## 💡 Hints
33+
34+
## ➡️ Approach
35+
36+
## ✅ Detailed Solution
37+
[View Solution : Can You Access?](./Solution.java)
38+
39+
| Submissions | Leaderboard| Discussions | Editorial |
40+
|:-----------|:------------:|------------:|------------:|
41+
| [📝 My Submission](https://www.hackerrank.com/challenges/can-you-access/submissions) | [🏆 Track our position](https://www.hackerrank.com/challenges/can-you-access/leaderboard) | [🤔 Help from Community](https://www.hackerrank.com/challenges/can-you-access/forum) | [✍️ Editorial](https://www.hackerrank.com/challenges/can-you-access/editorial) |
42+

Diff for: Java/Hackerrank/Covariant Return Types/README.md

+72-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,72 @@
1-
## **[Covariant Return Types](https://www.hackerrank.com/challenges/java-covariance)**
2-
Java allows for Covariant Return Types, which means you can vary your return type as long you are returning a subclass of your specified return type.<br><a href="https://docs.oracle.com/javase/tutorial/java/IandI/override.html">Method Overriding</a> allows a subclass to <em>override</em> the behavior of an existing superclass method and specify a return type that is some subclass of the original return type. It is best practice to use the <code>@Override</code> <a href="https://docs.oracle.com/javase/tutorial/java/annotations/basics.html">annotation</a> when overriding a superclass method.<br>Implement the classes and methods detailed in the diagram below:<br><br>You will be given a partially completed code in the editor where the <em>main</em> method takes the name of a state (i.e., <code>WestBengal</code>, or <code>AndhraPradesh</code>) and prints the national flower of that state using the classes and methods written by you. <br>Note: Do not use access modifiers in your class declarations.<br>Resources<br><br>**Sample Input 0**<br><code></code><br><br>**Sample Output 0**<br><code></code><br><br>**Explanation 0**<br><br>
1+
## [Covariant Return Types](https://www.hackerrank.com/challenges/java-covariance)
2+
3+
![Java](https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white) ![HackerRank](https://img.shields.io/badge/-Hackerrank-2EC866?style=for-the-badge&logo=HackerRank&logoColor=white)
4+
5+
| Difficulty | Max Score | Success Ratio |
6+
|:-----------|:------------:|------------:|
7+
| Easy | 20 | 97.60% |
8+
9+
Java allows for [Covariant Return Types](https://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html), which means you can vary your return type as long you are returning a subclass of your specified return type.
10+
11+
12+
[Method Overriding](https://docs.oracle.com/javase/tutorial/java/IandI/override.html) allows a subclass to *override* the behavior of an existing superclass method and specify a return type that is some subclass of the original return type. It is best practice to use the `@Override` [annotation](https://docs.oracle.com/javase/tutorial/java/annotations/basics.html) when overriding a superclass method.
13+
14+
15+
Implement the classes and methods detailed in the diagram below:
16+
17+
18+
![image](https://s3.amazonaws.com/hr-assets/0/1523891844-c66f1555af-class.png)
19+
20+
21+
You will be given a partially completed code in the editor where the *main* method takes the name of a state (i.e., `WestBengal`, or `AndhraPradesh`) and prints the national flower of that state using the classes and methods written by you.
22+
23+
24+
**Note:** *Do not* use access modifiers in your class declarations.
25+
26+
27+
**Resources**
28+
29+
[Covariant Return Type](http://c2.com/cgi/wiki?CovariantReturnTypes)
30+
31+
[Java Covariant Type](https://blogs.oracle.com/sundararajan/entry/covariant_return_types_in_java)
32+
33+
**Input Format**
34+
35+
The locked code reads a single string denoting the name of a subclass of *State* (i.e., `WestBengal`, `Karnataka`, or `AndhraPradesh`), then tests the methods associated with that subclass. You are not responsible for reading any input from stdin.
36+
37+
**Output Format**
38+
39+
Output is handled for you by the locked code, which creates the object corresponding to the input string's class name and then prints the name returned by that class' national flower's *whatsYourName* method. You are not responsible for printing anything to stdout.
40+
41+
**Sample Input 0**
42+
43+
44+
```
45+
AndhraPradesh
46+
47+
```
48+
49+
**Sample Output 0**
50+
51+
52+
```
53+
Lily
54+
55+
```
56+
57+
**Explanation 0**
58+
59+
An *AndhraPradesh* object's *yourNationalFlower* method returns an instance of the *Lily* class, and the *Lily* class' *whatsYourName* method returns `Lily`, which is printed by the hidden code checker.
60+
61+
62+
## 💡 Hints
63+
64+
## ➡️ Approach
65+
66+
## ✅ Detailed Solution
67+
[View Solution : Covariant Return Types](./Solution.java)
68+
69+
| Submissions | Leaderboard| Discussions | Editorial |
70+
|:-----------|:------------:|------------:|------------:|
71+
| [📝 My Submission](https://www.hackerrank.com/challenges/java-covariance/submissions) | [🏆 Track our position](https://www.hackerrank.com/challenges/java-covariance/leaderboard) | [🤔 Help from Community](https://www.hackerrank.com/challenges/java-covariance/forum) | [✍️ Editorial](https://www.hackerrank.com/challenges/java-covariance/editorial) |
72+

Diff for: Java/Hackerrank/Java 1D Array (Part 2)/README.md

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
## [Java 1D Array (Part 2)](https://www.hackerrank.com/challenges/java-1d-array)
2+
3+
![Java](https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white) ![HackerRank](https://img.shields.io/badge/-Hackerrank-2EC866?style=for-the-badge&logo=HackerRank&logoColor=white)
4+
5+
| Difficulty | Max Score | Success Ratio |
6+
|:-----------|:------------:|------------:|
7+
| Medium | 25 | 72.28% |
8+
9+
Let's play a game on an array! You're standing at index *[SVG image]* of an *[SVG image]* \-element array named *[SVG image]* . From some index *[SVG image]* (where *[SVG image]* ), you can perform one of the following moves:
10+
11+
12+
* *Move Backward:* If cell *[SVG image]* exists *and* contains a *[SVG image]* , you can walk back to cell *[SVG image]* .
13+
* *Move Forward:*
14+
+ If cell *[SVG image]* contains a zero, you can walk to cell *[SVG image]* .
15+
+ If cell *[SVG image]* contains a zero, you can jump to cell *[SVG image]* .
16+
+ If you're standing in cell *[SVG image]* or the value of *[SVG image]* , you can walk or jump off the end of the array and win the game.
17+
18+
19+
In other words, you can move from index *[SVG image]* to index *[SVG image]* , *[SVG image]* , or *[SVG image]* as long as the destination index is a cell containing a *[SVG image]* . If the destination index is greater than *[SVG image]* , you win the game.
20+
21+
22+
**Function Description**
23+
24+
25+
Complete the *canWin* function in the editor below.
26+
27+
28+
*canWin* has the following parameters:
29+
30+
31+
* *int leap:* the size of the leap
32+
* *int game\[n]:* the array to traverse
33+
34+
35+
**Returns**
36+
37+
38+
* *boolean:* true if the game can be won, otherwise false
39+
**Input Format**
40+
41+
The first line contains an integer, *[SVG image]* , denoting the number of queries (i.e., function calls).
42+
43+
The *[SVG image]* subsequent lines describe each query over two lines:
44+
45+
46+
1. The first line contains two space\-separated integers describing the respective values of *[SVG image]* and *[SVG image]* .
47+
2. The second line contains *[SVG image]* space\-separated binary integers (i.e., zeroes and ones) describing the respective values of *[SVG image]* .
48+
**Constraints**
49+
50+
* *[SVG image]*
51+
* *[SVG image]*
52+
* *[SVG image]*
53+
* It is guaranteed that the value of *[SVG image]* is always *[SVG image]* .
54+
**Sample Input**
55+
56+
57+
```
58+
STDIN Function
59+
----- --------
60+
4 q = 4 (number of queries)
61+
5 3 game[] size n = 5, leap = 3 (first query)
62+
0 0 0 0 0 game = [0, 0, 0, 0, 0]
63+
6 5 game[] size n = 6, leap = 5 (second query)
64+
0 0 0 1 1 1 . . .
65+
6 3
66+
0 0 1 1 1 0
67+
3 1
68+
0 1 0
69+
70+
```
71+
**Sample Output**
72+
73+
74+
```
75+
YES
76+
YES
77+
NO
78+
NO
79+
80+
```
81+
**Explanation**
82+
83+
We perform the following *[SVG image]* queries:
84+
85+
86+
1. For *[SVG image]* and *[SVG image]* , we can walk and/or jump to the end of the array because every cell contains a *[SVG image]* . Because we can win, we return *true*.
87+
2. For *[SVG image]* and *[SVG image]* , we can walk to index *[SVG image]* and then jump *[SVG image]* units to the end of the array. Because we can win, we return *true*.
88+
3. For *[SVG image]* and *[SVG image]* , there is no way for us to get past the three consecutive ones. Because we cannot win, we return *false*.
89+
4. For *[SVG image]* and *[SVG image]* , there is no way for us to get past the one at index *[SVG image]* . Because we cannot win, we return *false*.
90+
91+
## 💡 Hints
92+
93+
## ➡️ Approach
94+
95+
## ✅ Detailed Solution
96+
[View Solution : Java 1D Array (Part 2)](./Solution.java)
97+
98+
| Submissions | Leaderboard| Discussions | Editorial |
99+
|:-----------|:------------:|------------:|------------:|
100+
| [📝 My Submission](https://www.hackerrank.com/challenges/java-1d-array/submissions) | [🏆 Track our position](https://www.hackerrank.com/challenges/java-1d-array/leaderboard) | [🤔 Help from Community](https://www.hackerrank.com/challenges/java-1d-array/forum) | [✍️ Editorial](https://www.hackerrank.com/challenges/java-1d-array/editorial) |
101+

Diff for: Java/Hackerrank/Java 1D Array Part 2/README.md

-7
This file was deleted.

Diff for: Java/Hackerrank/Java 1D Array/README.md

+110-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,110 @@
1-
## **[Java 1D Array](https://www.hackerrank.com/challenges/java-1d-array-introduction)**
2-
An array is a simple data structure used to store a collection of data in a contiguous block of memory. Each element in the collection is accessed using an index, and the elements are easy to find because they're stored sequentially in memory.<br>Because the collection of elements in an array is stored as a big block of data, we typically use arrays when we know exactly how many pieces of data we're going to have. For example, you might use an array to store a list of student ID numbers, or the names of state capitals. To create an array of integers named that can hold four integer values, you would write the following code:<br>This sets aside a block of memory that's capable of storing integers. Each integer storage cell is assigned a unique index ranging from to one less than the size of the array, and each cell initially contains a . In the case of , we can store integers at indices , , , and . Let's say we wanted the last cell to store the number ; to do this, we write:<br><br><br><br><br><br><br><br>**Sample Input 0**<br><br>**Sample Output 0**<br><br>**Explanation 0**<br><br>
1+
## [Java 1D Array](https://www.hackerrank.com/challenges/java-1d-array-introduction)
2+
3+
![Java](https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white) ![HackerRank](https://img.shields.io/badge/-Hackerrank-2EC866?style=for-the-badge&logo=HackerRank&logoColor=white)
4+
5+
| Difficulty | Max Score | Success Ratio |
6+
|:-----------|:------------:|------------:|
7+
| Easy | 5 | 97.29% |
8+
9+
An array is a simple data structure used to store a collection of data in a contiguous block of memory. Each element in the collection is accessed using an *index*, and the elements are easy to find because they're stored sequentially in memory.
10+
11+
12+
Because the collection of elements in an array is stored as a big block of data, we typically use arrays when we know exactly how many pieces of data we're going to have. For example, you might use an array to store a list of student ID numbers, or the names of state capitals. To create an array of integers named *[SVG image]* that can hold four integer values, you would write the following code:
13+
14+
15+
16+
```
17+
int[] myArray = new int[4];
18+
19+
```
20+
21+
This sets aside a block of memory that's capable of storing *[SVG image]* integers. Each integer storage cell is assigned a unique *index* ranging from *[SVG image]* to one less than the size of the array, and each cell initially contains a *[SVG image]* . In the case of *[SVG image]* , we can store integers at indices *[SVG image]* , *[SVG image]* , *[SVG image]* , and *[SVG image]* . Let's say we wanted the last cell to store the number *[SVG image]* ; to do this, we write:
22+
23+
24+
25+
```
26+
myArray[3] = 12;
27+
28+
```
29+
30+
Similarly, we can print the contents of the last cell with the following code:
31+
32+
33+
34+
```
35+
System.out.println(myArray[3]);
36+
37+
```
38+
39+
The code above prints the value stored at index *[SVG image]* of *[SVG image]* , which is *[SVG image]* (the value we previously stored there). It's important to note that while Java initializes each cell of an array of integers with a *[SVG image]* , not all languages do this.
40+
41+
42+
**Task**
43+
44+
45+
The code in your editor does the following:
46+
47+
48+
1. Reads an integer from stdin and saves it to a variable, *[SVG image]* , denoting some number of integers.
49+
2. Reads *[SVG image]* integers corresponding to *[SVG image]* from stdin and saves each integer *[SVG image]* to a variable, *[SVG image]* .
50+
3. Attempts to print each element of an array of integers named *[SVG image]* .
51+
52+
53+
Write the following code in the unlocked portion of your editor:
54+
55+
56+
1. Create an array, *[SVG image]* , capable of holding *[SVG image]* integers.
57+
2. Modify the code in the loop so that it saves each sequential value to its corresponding location in the array. For example, the first value must be stored in *[SVG image]* , the second value must be stored in *[SVG image]* , and so on.
58+
59+
60+
Good luck!
61+
62+
**Input Format**
63+
64+
The first line contains a single integer, *[SVG image]* , denoting the size of the array.
65+
66+
Each line *[SVG image]* of the *[SVG image]* subsequent lines contains a single integer denoting the value of element *[SVG image]* .
67+
68+
**Output Format**
69+
70+
You are not responsible for printing any output to stdout. Locked code in the editor loops through array *[SVG image]* and prints each sequential element on a new line.
71+
72+
**Sample Input**
73+
74+
75+
```
76+
5
77+
10
78+
20
79+
30
80+
40
81+
50
82+
83+
```
84+
**Sample Output**
85+
86+
87+
```
88+
10
89+
20
90+
30
91+
40
92+
50
93+
94+
```
95+
**Explanation**
96+
97+
When we save each integer to its corresponding index in *[SVG image]* , we get *[SVG image]* . The locked code prints each array element on a new line from left to right.
98+
99+
100+
## 💡 Hints
101+
102+
## ➡️ Approach
103+
104+
## ✅ Detailed Solution
105+
[View Solution : Java 1D Array](./Solution.java)
106+
107+
| Submissions | Leaderboard| Discussions | Editorial |
108+
|:-----------|:------------:|------------:|------------:|
109+
| [📝 My Submission](https://www.hackerrank.com/challenges/java-1d-array-introduction/submissions) | [🏆 Track our position](https://www.hackerrank.com/challenges/java-1d-array-introduction/leaderboard) | [🤔 Help from Community](https://www.hackerrank.com/challenges/java-1d-array-introduction/forum) | [✍️ Editorial](https://www.hackerrank.com/challenges/java-1d-array-introduction/editorial) |
110+

0 commit comments

Comments
 (0)