Posts

Bharath and his strings

Image
  Problem link:  Codechef Bharath loves to roam the campus of NITW and also he is good at problem-solving. Pratyush decided to give a problem to Bharath. Pratyush gives Bharath a list of places inside NITW (each place is represented by some character from 'a' to 'z'). Starting from the beginning, Bharath has to visit all the places in the same order as given in the list. While roaming Bharath writes the name of a place when he visits it for the first time. At the end of the day, Bharat will tell all the distinct places traveled by him during the entire day in the order he visited them. Input First-line will contain T, the number of test cases. The description of T test cases follows. The first and only line of each test case contains a string S (containing only lowercase alphabets). Output For each test case print the order of visit of Bharath. Constraints ·        1  <=  T  <=  10 ·    ...

Lapindromes

Image
  Problem link:  Codechef Lapindrome  is defined as a string which when split in the middle, gives two halves having the same characters and the same frequency of each character. If there are an odd number of characters in the string, we ignore the middle character and check for lapindrome. For example,  gaga  is a lapindrome, since the two halves  ga  and  ga  have the same characters with the same frequency. Also,  abccab ,  rotor,  and  xyzxy  are a few examples of lapindromes. Note that  abbaab  is NOT a lapindrome. The two halves contain the same characters but their frequencies do not match. Your task is simple. Given a string, you need to tell if it is a lapindrome. Input: The first line of input contains a single integer  T , the number of test cases. Each test is a single line containing a string  S  composed of only lowercase English alphabet. Output: For each test case, ...

HCF and LCM using Python

Image
  a=36 b=56 d_a=a  d_b=b  r=a%b  while r !=0:     a,b=b,r      r=a%b  hcf=b  lcm=(d_a*d_b)/hcf print("hcf:",hcf," ","lcm:",lcm)

String to Integer

Image
String to Integer  Implement   atoi   which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which is ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed. If no valid conversion could be performed, a zero value is returned. Note: Only the space character  ' '  is considered a whitespace character. Assume we are dealing with an environment that could only store integers within...