Posts

Palindromic String | Basics of Input/Output

Image
Problem Statement :  You have been given a String  S . You need to find and print whether this string is a palindrome or not. If yes, print "YES" (without quotes), else print "NO" (without quotes). Problem Link :  https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/palindrome-check-2/ Input Format :   The first and only line of input contains the String  S . The String shall consist of lowercase English alphabets only. Output Format : Print the required answer on a single line. Constraints :    1 ≤ | S | ≤ 100 String  S  consists of lowercase English Alphabets only. Solution :   //Code here #include <iostream> using namespace std; int main() { char str[100];     cin>>str;         // input string int i,j;        // looping variables int len;...

Anagrams | Basics of Input/Output

Image
Problem Statement :  Given two strings,  a  and  b  , that may or may not be of the same length, determine the minimum number of character deletions required to make  a  and  b  anagrams. Any characters can be deleted from either of the strings. Problem Link : https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/anagrams-651/ Input : test cases,t two strings a and b, for each test case Output: Desired O/p Constraints : string lengths<=10000 Note : Anagram of a word is formed by rearranging the letters of the word. For e.g . -> For the word RAM - MAR,ARM,AMR,RMA etc. are few anagrams. Solution :   //Code is here #include<iostream> using namespace std; int main() {     int t;   cin>>t;   // for test cases     while(t--)     {      ...

Seating Arrangement | Basics of Input/Output

Image
Problem Statement : Akash and Vishal are quite fond of travelling. They mostly travel by railways. They were travelling in a train one day and they got interested in the seating arrangement of their compartment. The compartment looked something like So they got interested to know the seat number facing them and the seat type facing them. The seats are denoted as follows :  Window Seat :  WS Middle Seat :  MS Aisle Seat :  AS You will be given a seat number, find out the seat number facing you and the seat type, i.e.  WS ,  MS  or  AS . Problem Link : https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/seating-arrangement-1/ INPUT :  First line of input will consist of a single integer  T  denoting number of test-cases. Each test-case consists of a single integer  N  denoting the seat-number. OUTPUT :   For each test ...

Prime Number | Basics of Input/Output

Image
Problem Statement : You are given an integer N. You need to print the series of all prime numbers till N. Problem Link :   https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/prime-number-8/ Input Format : The first and only line of the input contains a single integer N denoting the number till where you need to find the series of prime number. Output Format : Print the desired output in single line separated by spaces. Constraints : 1<=N<=1000 Solution :  // Code for the Problem #include <iostream> using namespace std; int isPrime(int n) {        for(int i=2;i<=n/2;i++)     {         if(n%i==0)         {             return 0;         }          }    return 1; } int main() { ...