Java Hyd Team
How to reverse a string in Java without using the reverse method? This is the common question asked in the java interviews. We know, we can easily reverse the java string using the reverse() method of the StringBuilder class. You will be asked to reverseβ¦
In the first method, we are initializing an empty string variable, reversedString.
You can use the charAt() method of the String class to get the character at any particular index of the string.
We are getting the characters of the inputString one by one in reverse order and appending it to the reversedString.
Finally, we are returning the reversedString.
Q3.)
In the second method, we are converting the inputString to the characters array using the toCharArray() method of the String class.
Once we got the array, we are appending the characters from the characters array stringCharArray to reversedString one by one in reverse order.
And finally, we are returning the reversedString.
You can use the charAt() method of the String class to get the character at any particular index of the string.
We are getting the characters of the inputString one by one in reverse order and appending it to the reversedString.
Finally, we are returning the reversedString.
Q3.)
In the second method, we are converting the inputString to the characters array using the toCharArray() method of the String class.
Once we got the array, we are appending the characters from the characters array stringCharArray to reversedString one by one in reverse order.
And finally, we are returning the reversedString.
Java Hyd Team pinned Β«DO YOU GUY'S NEED SOME MORE HAND WRITTEN POINT TO POINT NOTES ??Β»
Java Hyd Team
DO YOU GUY'S NEED SOME MORE HAND WRITTEN POINT TO POINT NOTES ??
Please vote it takes efforts to share notes so point to point
If you like the way we describe if you really think this support matters do share us with your friends let's grow
Only one response i have rcvd yet anyone else wanna share or we can close accepting n sharing these questions
Java Hyd Team
DO YOU GUY'S NEED SOME MORE HAND WRITTEN POINT TO POINT NOTES ??
Only 8 of 28 need these things rest can leave this channel ππ
You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return the maximum amount of water a container can store.
Notice that you may not slant the container.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return the maximum amount of water a container can store.
Notice that you may not slant the container.
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
Output: 49
Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.