Posts

Array | Anagram check | The Nerd Guy

Problem : Given two strings, check to see if they are anagrams. An anagram is when the two strings can be written using the exact same letters (so you can just rearrange the letters to get a different phrase or word). For Example : ''I love it when you call me senorita" is anagram of "senorita love me allc ouy it I hwen allc". "my cat" and "matcy" are anagrams. "call me" and "mallec" are also anagrams.

Bubble Sort Implementation - Java

Bubble Sort  is a simple algorithm which is used to sort a given set of n elements provided in form of an array with n  number of elements. Bubble Sort compares all the element one by one and sorts them based on their values. If the given array has to be sorted in ascending order, then bubble sort will start by comparing the first element of the array with the second element, if the first element is greater than the second element, it will  swap  both the elements, and then move on to compare the second and the third element, and so on. If we have total  n  elements, then we need to repeat this process for  n-1  times. It is known as  bubble sort , because with every complete iteration the largest element in the given array, bubbles up towards the last place or the highest index, just like a water bubble rises up to the water surface. Sorting takes place by stepping through all the elements one-by-one and comparing it with the adjacent element and swapping them if required.

Day 29: Bitwise AND - HackerRank 30 days of code solution

Objective Welcome to the last day! Today, we're discussing bitwise operations. Task Given set  . Find two integers,   and   (where  ), from set   such that the value of   is the maximum possible  and also less than a given integer,  . In this case,   represents the  bitwise AND  operator. Input Format The first line contains an integer,  , the number of test cases. Each of the   subsequent lines defines a test case as   space-separated integers,   and  , respectively. Constraints Output Format For each test case, print the maximum possible value of   on a new line. Sample Input 3 5 2 8 5 2 2 Sample Output 1 4 0 Explanation All possible values of   and   are: The maximum possible value of   that is also   is  , so we print   on a new line. Solution : import java.io.*; import java.util.*; public class Solution {     public static void main(String[] args) {         /* E