Insertion Sort Algorithm
Its a kind of incremental insertion technique, where the algorithm build up…
September 11, 2020
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Note: For the purpose of this problem, we define empty string as valid palindrome.
Example
Input: "A man, a plan, a canal: Panama"
Output: true
Input: "race a car"
Output: false
Please note the special conditions:
Lets run our simple two pointer system where:
public static boolean isAlphanumeric(char c) {
return Character.isDigit(c) || Character.isLetter(c);
}
public boolean isPalindrome(String s) {
if (s.length() == 0) return true;
int l = 0;
int r = s.length()-1;
while (l < r) {
while (!isAlphanumeric(s.charAt(l)) && l < r) {
l++;
}
while (!isAlphanumeric(s.charAt(r)) && l < r) {
r--;
}
if (Character.toLowerCase(s.charAt(l)) != Character.toLowerCase(s.charAt(r))) {
return false;
}
l++;
r--;
}
return true;
}
Its O(n)
Its a kind of incremental insertion technique, where the algorithm build up…
Problem Statement Given a string, find the length of the longest substring…
Problem Statement Roman numerals are represented by seven different symbols: I…
Problem Statement Given n non-negative integers a1, a2, …, an , where each…
Problem Statement You are given an array of integers. And, you have find the…
Problem Statement You are given a string text of words that are placed among…
Introduction In this post we will see following: How to schedule a job on cron…
Introduction There are some cases, where I need another git repository while…
Introduction In this post, we will see how to fetch multiple credentials and…
Introduction I have an automation script, that I want to run on different…
Introduction I had to write a CICD system for one of our project. I had to…
Introduction Java log4j has many ways to initialize and append the desired…