A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, ignoring spaces, punctuation, and capitalization. In this context, we are given a string and we need to determine whether it is a palindrome or not.
CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷
The solution approach is to iterate over the string from both ends simultaneously. If at any point the characters at the corresponding positions from the start and end are not the same, we conclude that the string is not a palindrome. If we can traverse the whole string this way without finding any mismatch, then the string is a palindrome.
/**
*
*/
package com.javaaid.hackerrank.solutions.languages.java.strings;
import java.util.Scanner;
/**
*
*/
public class JavaStringReverse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String A = sc.next();
sc.close();
boolean found = true;
for (int i = 0; i < A.length() / 2; i++) {
if (A.charAt(i) != A.charAt(A.length() - 1 - i)) {
found = false;
break;
}
}
System.out.println(found ? "Yes" : "No");
}
}
If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.
AI is here now, and other candidates might be using it to get ahead and win the job. 🧐
The form has been successfully submitted.