Anagram

/*

 Sid is obsessed with reading short stories. Being a CS student, he is doing some interesting frequency analysis with
 the books. He chooses strings S1 and S2 in such a way that |len(S1)-len(s2)|<=1 .
Your task is to help him find the minimum number of characters of the first string he needs to change to enable him
to make it an anagram of the second string.
Note: A word x is an anagram of another word y if we can produce y by rearranging the letters of x.
Input Format
The first line will contain an integer, T, representing the number of test cases. Each test case will contain a string
having length len(S1)+len(s2), which will be concatenation of both the strings described above in the
problem.The given string will contain only characters from a to z .


Constraints
1<=T<=100
1<=len(S1)+len(s2)<=10^4

Output Format
An integer corresponding to each test case is printed in a different line, i.e. the number of changes required for each
test case. Print -1 if it is not possible.
Sample Input
6
aaabbb
ab
abc
mnop
xyyx
xaxbbbxx
Sample Output
3
1
-1
2
0
1
Explanation
Test Case #01: We have to replace all three characters from the first string to make both of strings anagram. Here,
S1= "aaa" and S2 = "bbb". So the solution is to replace all character 'a' in string a with character 'b'.
Test Case #02: You have to replace 'a' with 'b', which will generate "bb".
Test Case #03: It is not possible for two strings of unequal length to be anagram for each other.
Test Case #04: We have to replace both the characters of first string ("mn") to make it anagram of other one.
Test Case #05: S1 and S2 are already anagram to each other.
Test Case #06: Here S1 = "xaxb" and S2 = "bbxx". He had to replace 'a' from S1 with 'b' so that S1 = "xbxb" and we
can rearrange its letter to "bbxx" in order to get S2.

 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HackerDemo
{
    class Anagram
    {
        public void AnagramMain()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int a0 = 0; a0 < t; a0++)
            {
                string longStr = Console.ReadLine();
                if (longStr.Length % 2 != 0)
                {
                    Console.WriteLine(-1);
                    continue;
                }
                string fStr = longStr.Substring(0, longStr.Length / 2);
                string sStr = longStr.Substring(longStr.Length / 2, longStr.Length / 2);
                Console.WriteLine(CountDeleteChar(fStr, sStr));
            }
           
        }
        public int CountDeleteChar(string str1, string str2)
        {
            List<char> charList = str1.ToCharArray().ToList();
            foreach (char c in str2)
            {
                charList.Remove(c);
            }
            return charList.Count();
        }
    }
}

Making Anagrams

/*


 Alice is taking a cryptography class and finding anagrams to be very useful. We consider two strings to be anagrams
 of each other if the first string's letters can be rearranged to form the second string. In other words, both strings
 must contain the same exact letters in the same exact frequency For example, bacdc and dcbac are anagrams, but
 bacdc and dcbad are not.
Alice decides on an encryption scheme involving two large strings where encryption is dependent on the minimum
number of character deletions required to make the two strings anagrams. Can you help her find this number?
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.
This challenge is also available in the following translations:
Chinese
Russian
Input Format
The first line contains a single string,a .
The second line contains a single string, b.
Constraints
1<=|a|,|b|<=10^4
It is guaranteed that a and b consist of lowercase English letters.
Output Format
Print a single integer denoting the number of characters which must be deleted to make the two strings anagrams
of each other.
Sample Input
cde
abc
Sample Output
4
Explanation
We delete the following characters from our two strings to turn them into anagrams of each other:
Remove d and e from cde to get c.
Remove a and b from abc to get c.
We had to delete  characters to make both strings anagrams, so we print 4 on a new line.

 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HackerDemo
{
    class MakingAnagrams
    {
      public void MakingAnagramsMain()
        {
            string fStr = Console.ReadLine();
            string sStr = Console.ReadLine();
            string delFStr = DeleteExtrachar(fStr, sStr);
            string delSStr = DeleteExtrachar(sStr, fStr);
            int delCount = delFStr.Count() + delSStr.Count();
            Console.WriteLine(delCount);
        }

        public string DeleteExtrachar(string str1, string str2)
        {
            List<char> charList = str2.ToCharArray().ToList();
            foreach(char c in str1)
            {
                charList.Remove(c);
            }
            return new string(charList.ToArray());
        }
    }
}

Beautiful Binary String

/*
 Alice has a binary string,B , of length n. She thinks a binary string is beautiful if and only if it doesn't contain the
 substring "010".
In one step, Alice can change a 0 to a 1  (or vice-versa). Count and print the minimum number of steps needed to
make Alice see the string as beautiful.
Input Format
The first line contains an integer,n  (the length of binary string B).
The second line contains a single binary string, B, of length n.
Constraints
1<=n<=100
Each character in B belongs to {0,1} .
Output Format
Print the minimum number of steps needed to make the string beautiful.
Sample Input 0
7
0101010
Sample Output 0
2
Sample Input 1
5
01100
Sample Output 1
0
Sample Input 2
10
0100101010
Sample Output 2
3
Explanation
Sample Case 0:
In this sample, B="0101010"
The figure below shows a way to get rid of each instance of "010":


Because we were able to make the string beautiful by changing 2 characters (B2 and B5), we print 2.
Sample Case 1:
In this sample B="01100"
The substring "010" does not occur in B, so the string is already beautiful and we print 0.

 */


using System;


namespace HackerDemo
{
    class BeautifulBinaryString
    {
        public void BeautifulBinaryStringMain()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string b = Console.ReadLine();
            Console.WriteLine(GetCount(n,b));
        }

        public int GetCount(int n, string Bstr)
        {
            int count = 0;
            string str = "010";
            for (int i = 0; i < n- str.Length+1; i++)
            {
                if (str== Bstr.Substring(i,str.Length))
                {
                    count++;
                    i = i + str.Length-1;
                }
                
            }
            return count;
        }
    }
}

Alternating Characters


/*
 Shashank likes strings in which consecutive characters are different. For example, he likes ABABA, while he doesn't
 like ABAA. Given a string containing characters A and B only, he wants to change it into a string he likes. To do this,
 he is allowed to delete the characters in the string.
Your task is to find the minimum number of required deletions.
Input Format
The first line contains an integer T, i.e. the number of test cases.
The next T lines contain a string each.
Output Format
For each test case, print the minimum number of deletions required.
Constraints
1<=T<=10

1<= length of string <=10^5
Sample Input
5
AAAA
BBBBB
ABABABAB
BABABA
AAABBB
Sample Output
3
4
0
0
4
Explanation
AAAA ==> A, 3 deletions
BBBBB ==> B, 4 deletions
ABABABAB ==> ABABABAB, 0 deletions
BABABA ==> BABABA, 0 deletions
AAABBB ==> AB, 4 deletions because to convert it to AB we need to delete 2 A's and 2 B's
 */

using System;

namespace HackerDemo
{
    class AlternatingCharacters
    {
        public void AlternatingCharactersMain()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int a0 = 0; a0 < t; a0++)
            {
                string str = Console.ReadLine();
                Console.WriteLine(GetCount(str));
            }
        }

        public int GetCount(string str)
        {
            int count = 0;
            for (int i = 0; i < str.Length-1; i++)
            {
                if (str[i]==str[i+1])
                {
                    count++;
                }
            }
            return count;
        }
    }
}

GemsStone problem


/**
 John has discovered various rocks. Each rock is composed of various elements, and each element is represented by
 a lower-case Latin letter from 'a' to 'z'. An element can be present multiple times in a rock. An element is called a
 gem-element if it occurs at least once in each of the rocks.
Given the list of N rocks with their compositions, display the number of gem-elements that exist in those rocks.
Input Format
The first line consists of an integer,N , the number of rocks.
Each of the next N lines contains a rock's composition. Each composition consists of lower-case letters of English alphabet.
Constraints
1<=N<=100
Each composition consists of only lower-case Latin letters ('a'-'z').
1<= length of each composition <=100
Output Format
Print the number of gem-elements that are common in these rocks. If there are none, print 0.
Sample Input
3
abcdde
baccd
eeabg
Sample Output
2
Explanation
Only "a" and "b" are the two kinds of gem-elements, since these are the only characters that occur in every rock's composition.
 */



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HackerDemo
{
    class Gemstones
    {
        public void GemstonesMain()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            List<string> listInputStr = new List<string>();
            for (int a0 = 0; a0 < n; a0++)
            {
                listInputStr.Add(Console.ReadLine()); 
            }
            string shortstr = listInputStr.OrderBy(s => s.Length).First();
            List<char> charList = GetCommonChars(shortstr, listInputStr).Distinct().ToList();
            Console.WriteLine(charList.Count);
        }

        public List<char> GetCommonChars(string shortStr, List<string> strList)
        {
            List<char>charList = new List<char>();
            charList = shortStr.ToCharArray().ToList();
            for (int i = 0; i < shortStr.Length; i++)
            {
                foreach (var str in strList)
                {
                    if (!str.Contains(shortStr[i]))
                    {
                        charList.Remove(shortStr[i]);
                    }
                }
            }

            return charList;
        }
    }
}

Game of Thrones - I

/*

 Dothraki are planning an attack to usurp King Robert's throne. King Robert learns of this conspiracy from Raven and
 plans to lock the single door through which the enemy can enter his kingdom.
door

But, to lock the door he needs a key that is an anagram of a certain palindrome string.
The king has a string composed of lowercase English letters. Help him figure out whether any anagram of the string
can be a palindrome or not.
Input Format
A single line which contains the input string.
Constraints
1<= length of string  <=10^5
Each character of the string is a lowercase English letter.
Output Format
A single line which contains YES or NO in uppercase.
Sample Input : 01
aaabbbb
Sample Output : 01
YES
Explanation
A palindrome permutation of the given string is bbaaabb.
Sample Input : 02
cdefghmnopqrstuvw
Sample Output : 02
NO
Explanation
You can verify that the given string has no palindrome permutation.
Sample Input : 03
cdcdcdcdeeeef
Sample Output : 03
YES
Explanation
A palindrome permutation of the given string is ddcceefeeccdd.
 

 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HackerDemo
{
    class GameofThronesI
    {
       static string resultStr = "NO";
        public void GameofThronesImain()
        {
            string inputstr = "cdefghmnopqrstuvw";// Console.ReadLine();
            char[] arr = inputstr.ToCharArray();
            GetPer(arr);
            Console.WriteLine(resultStr);
        }

        public static bool IsPalindrome(string str)
        {
            return str.SequenceEqual(str.Reverse());
        }
       private static void Swap(ref char a, ref char b)
        {
            if (a == b) return;
            a ^= b;
            b ^= a;
            a ^= b;
        }

        public static void GetPer(char[] list)
        {
            int x = list.Length - 1;
            GetPer(list, 0, x);
        }

        private static void GetPer(char[] list, int k, int m)
        {
            
            if (k == m)
            {
                if (IsPalindrome(new string(list))&& resultStr=="NO")
                {
                    resultStr = "YES";
                }
            }
            else
                for (int i = k; i <= m; i++)
                {
                    Swap(ref list[k], ref list[i]);
                    GetPer(list, k + 1, m);
                    Swap(ref list[k], ref list[i]);
                }
        }
    }
}

Manasa and Stones problem


/*
 Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the trail
 and notices that two consecutive stones have a difference of either a or b. Legend has it that there is a treasure
 trove at the end of the trail and if Manasa can guess the value of the last stone, the treasure would be hers. Given
 that the number on the first stone was 0, find all the possible values for the number on the last stone.
Note: The numbers on the stones are in increasing order.
Input Format
The first line contains an integer T, i.e. the number of test cases. T test cases follow; each has 3 lines. The first line
contains n (the number of stones). The second line contains a, and the third line contains b.
Constraints
1<=T<=10
1<=n,a,b<=10^3
Output Format
Space-separated list of numbers which are the possible values of the last stone in increasing order.
Sample Input
2
3
1
2
4
10
100
Sample Output
2 3 4
30 120 210 300
Explanation
All possible series for the first test case are given below:
0,1,2
0,1,3
0,2,3
0,2,4
Hence the answer 2 3 4.
Series with different number of final steps for second test case are the following:
0, 10, 20, 30
0, 10, 20, 120
0, 10, 110, 120
0, 10, 110, 210
0, 100, 110, 120
0, 100, 110, 210
0, 100, 200, 210
0, 100, 200, 300
Hence the answer 30 120 210 300.
 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HackerDemo
{
   public class ManasaandStones
    {
        public void ManasaandStonesMain()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int a0 = 0; a0 < t; a0++)
            {
                int n = Convert.ToInt32(Console.ReadLine());
                int a = Convert.ToInt32(Console.ReadLine());
                int b = Convert.ToInt32(Console.ReadLine());
                int temp;
                int k1 = n - 1, k2 = 0;
                decimal next;
                if (a == b)
                {
                    next = (k1 * a) + (k2 * b);
                    Console.Write(next + " ");
                    break;
                }
                if (a > b)
                {
                    temp = a;
                    a = b;
                    b = temp;
                }
               
                for (int i = 0; i < n; i++)
                {
                    next = (k1 * a) + (k2 * b);
                    Console.Write(next + " ");
                    k1--;
                    k2++;
                }

                Console.WriteLine();


            }
        }
    }
}

Halloween party problem

/*

 Alex is attending a Halloween party with his girlfriend, Silvia. At the party, Silvia spots the corner of an infinite
 chocolate bar (two dimensional, infinitely long in width and length).
If the chocolate can be served only as 1 x 1 sized pieces and Alex can cut the chocolate bar exactly K times, what is
the maximum number of chocolate pieces Alex can cut and give Silvia?
Input Format
The first line contains an integer T, the number of test cases. T lines follow.
Each line contains an integer K.
Output Format
T lines; each line should contain an integer that denotes the maximum number of pieces that can be obtained for
each test case.
Constraints
1<=T<=10
2<=K<=10^7

Note: Chocolate must be served in 1 x 1 sized pieces. Alex can't relocate any of the pieces, nor can he place any
piece on top of another.
Sample Input #00
4
5
6
7
8
Sample Output #00
6
9
12
16
Explanation
The explanation below is for the first two test cases. The rest of them follow a similar logic.
For the first test-case where K=5 , you need 3 horizontal and 2 vertical cuts.
For the second test case, where K=6, you need 3 horizontal and 3 vertical cuts.

 */

using System;

namespace HackerDemo
{
    class Halloweenparty
    {
        public void HalloweenpartyMain()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int a0 = 0; a0 < t; a0++)
            {
                int n = Convert.ToInt32(Console.ReadLine());
                decimal fcut = Math.Floor((decimal)n / 2); 
                decimal scut = n - fcut;
                decimal k =  fcut * scut;
                Console.WriteLine(k);
            }
        }
    }
}

Cut the sticks problem


/*

You are given N sticks, where the length of each stick is a positive integer. A cut operation is performed on the
sticks such that all of them are reduced by the length of the smallest stick.
Suppose we have six sticks of the following lengths:
5 4 4 2 2 8
Then, in one cut operation we make a cut of length 2 from each of the six sticks. For the next cut operation four
sticks are left (of non-zero length), whose lengths are the following:
3 2 2 6
The above step is repeated until no sticks are left.
Given the length of N sticks, print the number of sticks that are left before each subsequent cut operations.
Note: For each cut operation, you have to recalcuate the length of smallest sticks (excluding zero-length sticks).
Input Format
The first line contains a single integer N.
The next line contains N integers: a0, a1,...aN-1 separated by space, where ai represents the length of the ith stick.
Output Format
For each operation, print the number of sticks that are cut, on separate lines.
Constraints
1<=N<=1000
1<=ai<=1000
Sample Input 0
6
5 4 4 2 2 8
Sample Output 0
6
4
2
1
Sample Input 1
8
1 2 3 4 3 3 2 1
Sample Output 1
8
6
4
1
Explanation
Sample Case 0 :
sticks-length        length-of-cut   sticks-cut
5 4 4 2 2 8             2               6
3 2 2 _ _ 6             2               4
1 _ _ _ _ 4             1               2
_ _ _ _ _ 3             3               1
_ _ _ _ _ _           DONE            DONE
Sample Case 1
sticks-length         length-of-cut   sticks-cut
1 2 3 4 3 3 2 1         1               8
_ 1 2 3 2 2 1 _         1               6
_ _ 1 2 1 1 _ _         1               4
_ _ _ 1 _ _ _ _         1               1
_ _ _ _ _ _ _ _       DONE            DONE
 */


using System;
using System.Linq;

namespace HackerDemo
{
    class Cutthesticks
    {
        public void CutthesticksMain()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] arr_temp = Console.ReadLine().Split(' ');
            int[] arr = Array.ConvertAll(arr_temp, Int32.Parse);
            
            int cutCount = arr.Count();
            int[] temp = arr;
            while (cutCount > 0)
            {
                Console.WriteLine(cutCount);
                temp = cutSticks(temp);
                cutCount = temp.Count();
                
            }
        }

        public int[] cutSticks(int[] arr)
        {
            int min = arr.Min();
            for (int i = 0; i < arr.Count(); i++)
            {
                arr[i] = arr[i] - min;
            }
            var temparr = arr.Where(a=>a >0).ToArray();
            return temparr;
        }
    }
}

Service Lane problem


/*
Calvin is driving his favorite vehicle on the 101 freeway. He notices that the check engine light of his vehicle is on,
and he wants to service it immediately to avoid any risks. Luckily, a service lane runs parallel to the highway. The
length of the service lane is N units. The service lane consists of N segments of equal length and different width.
Calvin can enter to and exit from any segment. Let's call the entry segment as index i and j the exit segment as index j.
Assume that the exit segment lies after the entry segment (i<=j) and 0<=i . Calvin has to pass through all
segments from index i to index j (both inclusive).
Paradise Highway


Calvin has three types of vehicles - bike, car, and truck - represented by 1, 2 and 3, respectively. These numbers also
denote the width of the vehicle.
You are given an array width of length N , where width[k] represents the width of the kth segment of the service
lane. It is guaranteed that while servicing he can pass through at most 1000 segments, including the entry and exit
segments.
If width[k]=1, only the bike can pass through the kth segment.
If width[k]=2, the bike and the car can pass through thke kth segment.
If width[k]=3, all three vehicles can pass through the th segment.
Given the entry and exit point of Calvin's vehicle in the service lane, output the type of the largest vehicle which can
pass through the service lane (including the entry and exit segments).
Input Format
The first line of input contains two integers,N and T, where N denotes the length of the freeway and T the
number of test cases. The next line has N space-separated integers which represent the width array.
T test cases follow. Each test case contains two integers, i and j, where  is the index of the segment through which
Calvin enters the service lane and j is the index of the lane segment through which he exits.
Constraints
 2<=N<=100000
 1<=T<=1000
 0<=i<j<N
 2<=j-i+1<=min(N,1000)
 1<=width[k]<=3,where 0<=k<N

Output Format
For each test case, print the number that represents the largest vehicle type that can pass through the service lane.
Note: Calvin has to pass through all segments from index i to index j (both inclusive).
Sample Input
8 5
2 3 1 2 3 2 3 3
0 3
4 6
6 7
3 5
0 7
Sample Output
1
2
3
2
1
Explanation
Below is the representation of the lane:
   |HIGHWAY|Lane|    ->    Width
0: |       |--|            2
1: |       |---|           3
2: |       |-|             1
3: |       |--|            2
4: |       |---|           3
5: |       |--|            2
6: |       |---|           3
7: |       |---|           3
1. (0, 3): Because width[2] = 1, only the bike can pass through it.
2. (4, 6): Here the largest allowed vehicle which can pass through the 5th segment is the car and for the 4th and 6th
    segment it's the truck. Hence the largest vehicle allowed in these segments is a car.
3. (6, 7): In this example, the vehicle enters at the 6th segment and exits at the 7th segment. Both segments allow
   even trucks to pass through them. Hence the answer is 3.
4. (3, 5): width[3] = width[5] = 2. While the 4th segment allows the truck, the 3rd and 5th allow up to a car. So 2 will
    be the answer here.
5. (0, 7): The bike is the only vehicle which can pass through the 2nd segment, which limits the strength of the whole
   lane to 1.

 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HackerDemo
{
    class ServiceLane
    {
        public void ServiceLaneMain()
        {
            string[] tokens_n = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(tokens_n[0]);
            int t = Convert.ToInt32(tokens_n[1]);
            string[] width_temp = Console.ReadLine().Split(' ');
            int[] width = Array.ConvertAll(width_temp, Int32.Parse);
            for (int a0 = 0; a0 < t; a0++)
            {
                string[] tokens_i = Console.ReadLine().Split(' ');
                int i = Convert.ToInt32(tokens_i[0]);
                int j = Convert.ToInt32(tokens_i[1]);

                int vechilewidth = GetVechileNo(i, j, width);
                Console.WriteLine(vechilewidth);
            }
        }

        int GetVechileNo(int i, int j, int[] width)
        {
            int vechileno = 3;
            for (int k = i; k <= j; k++)
            {
                if (vechileno > width[k])
                {
                    vechileno = width[k];
                } 
            }
            return vechileno;
        }
    }
}

Save the Prisoner problem.


/*

 A jail has N prisoners, and each prisoner has a unique id number,S , ranging from 1 to N . There are M sweets that must be distributed to the prisoners.
The jailer decides the fairest way to do this is by sitting the prisoners down in a circle (ordered by ascending S), and then, starting with some random S, distribute one candy at a time to each sequentially numbered prisoner until all M candies are distributed. For example, if the jailer picks prisoner s=2 , then his distribution order would be (2 ,3,4 ... n-1, n, 1, 2,3,4..) until all M sweets are distributed.
But wait—there's a catch—the very last sweet is poisoned! Can you find and print the ID number of the last prisoner to receive a sweet so he can be warned?
Input Format
The first line contains an integer, T, denoting the number of test cases.
The T subsequent lines each contain 3 space-separated integers:
 N(the number of prisoners), M (the number of sweets), and S (the prisoner ID), respectively.
Constraints
1<=T<=100
1<=N<=10^9
1<=M<=10^9
1<=s<=10^9
Output Format
For each test case, print the ID number of the prisoner who receives the poisoned sweet on a new line.
Sample Input
1
5 2 1
Sample Output
2
Explanation
There are N=5  prisoners and  M=2 sweets. Distribution starts at ID number s=1 , so prisoner 1 gets the first sweet and prisoner2  gets the second (last) sweet. Thus, we must warn prisoner 2 about the poison, so we print 2 on a new line.

 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;

namespace HackerDemo
{
    class SavethePrisoner
    {
        public void SavethePrisonerMain()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int a0 = 0; a0 < t; a0++)
            {
                string[] tokens_n = Console.ReadLine().Split(' ');
                int n = Convert.ToInt32(tokens_n[0]);
                int m = Convert.ToInt32(tokens_n[1]);
                int s = Convert.ToInt32(tokens_n[2]);
                Int64 sid = 0;
                sid = m % n;

                sid = sid + s - 1;
                if (sid > n)
                {
                    sid = sid - n;
                }

                Console.WriteLine(sid);
            }
        }
    }
}

Viral Advertising problems.




















































using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HackerDemo
{
    class ViralAdvertising
    {
        public void ViralAdvertisingMain()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int noOfLikes = 0;
            int DefaultShare = 3;
            int initialShare = 5;

            for (int i = 1; i <= n; i++)
            {
                decimal d = (decimal)initialShare / 2;
                int nshare = Convert.ToInt32(Math.Floor(d)) ;
                initialShare = nshare * DefaultShare;
                noOfLikes += nshare;
            }
            Console.WriteLine(noOfLikes);
        }
    }
}

Beautiful Days at the Movies problem

/*


 Lily likes to play games with integers and their reversals. For some integer x , we define reversed(x) to be the reversal of all digits in x . For example reversed(123)=321,reversed(21)=12 and reversed(120)=21, .
Logan wants to go to the movies with Lily on some day x satisfying i<=x<=j, but he knows she only goes to the movies on days she considers to be beautiful. Lily considers a day to be beautiful if the absolute value of the difference between x and reversed(x) is evenly divisible by K .
Given i,j , and K , count and print the number of beautiful days when Logan and Lily can go to the movies.
Input Format
A single line of three space-separated integers describing the respective values of i, j, and K .
Constraints
1<=i<=j<2*10^6
1<=k<=2*10^9
Output Format
Print the number of beautiful days in the inclusive range between i and j.
Sample Input
20 23 6
Sample Output
2
Explanation
Logan wants to go to the movies on days 20,21 ,22 , and 23. We perform the following calculations to determine which days are beautiful:
Day 20  is beautiful because the following evaluates to a whole number(20-02/6=3):
Day 21 is not beautiful because the following doesn't evaluate to a whole number (21-12/6)=1.5:
Day 22 is beautiful because the following evaluates to a whole number: (22-22/6)=0
Day 23 is not beautiful because the following doesn't evaluate to a whole number: (23-32/6)=1.5
Only two days,20  and 22, in this interval are beautiful. Thus, we print 2 as our answer.

 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HackerDemo
{
    class BeautifulDaysattheMovies
    {
      public  void BeautifulDaysattheMoviesMain()
        {
            string[] tokens_n = Console.ReadLine().Split(' ');
            int i = Convert.ToInt32(tokens_n[0]);
            int j = Convert.ToInt32(tokens_n[1]);
            int k = Convert.ToInt32(tokens_n[2]);
            int beautifulldays = 0;
            for (int d = i; d <= j; d++)
            {
                if (IsDaybeutifull(d, k))
                {
                    beautifulldays++;
                }
            }
            Console.WriteLine(beautifulldays);
           

        }

        bool IsDaybeutifull(int day, int k)
        {
            int revday = ReverseofInteger(day);
            int revDiff = revday - day;

            if (revDiff % k == 0 )
            {
                return true;
            }
            return false;
        }

        int ReverseofInteger(int number)
        {
            int reverseNumber = 0;
            while (number > 0)
            {
                reverseNumber = (reverseNumber * 10) + (number % 10);
                number = number / 10;
            }
            return reverseNumber;

            
        }
    }
}

Angry Professor Class cancellation problem


/* A Discrete Mathematics professor has a class of N students.Frustrated with their lack of discipline, he decides to cancel class if fewer than K students are present when class starts.
Given the arrival time of each student, determine if the class is canceled.
Input Format
The first line of input contains T, the number of test cases.
Each test case consists of two lines. The first line has two space-separated integers, N (students in the class) and K (the cancelation threshold). The second line contains N space-separated integers(a1,a2 ... aN describing the arrival times for each student.
Note: Non-positive arrival times (ai<=0) indicate the student arrived early or on time; positive arrival times(ai>0) indicate the student arrived ai minutes late.
Constraints
1<=T<=10
1<=N<=1000
1<=K<=N
-100 <= ai<=100,where i belongs to [1,N]
Output Format

For each test case, print the word YES if the class is canceled or NO if it is not.
Note
If a student arrives exactly on time(ai =0), the student is considered to have entered before the class started.
Sample Input
2
4 3
-1 -3 4 2
4 2
0 -1 2 1
Sample Output
YES
NO
Explanation
For the first test case, K=3. The professor wants at least 3 students in attendance, but only 2  have arrived on time(-3 and -1 ). Thus, the class is canceled.
For the second test case,K =2. The professor wants at least 2 students in attendance, and there are 2 who have arrived on time(0 and -1 ). Thus, the class is not canceled.*/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HackerDemo
{

   
    public class AngryProfessor
    {
        public void AngryProfessorMain()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int a0 = 0; a0 < t; a0++)
            {
                string[] tokens_n = Console.ReadLine().Split(' ');
                int n = Convert.ToInt32(tokens_n[0]);
                int k = Convert.ToInt32(tokens_n[1]);
                string[] a_temp = Console.ReadLine().Split(' ');
                int[] a = Array.ConvertAll(a_temp, Int32.Parse);
                if (isClassCancelled(k, a))
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }
        }

        public bool isClassCancelled(int k, int[] arr)
        {
            var studentOnTime = arr.Where(a => a <= 0);
            if(studentOnTime.Count()<k)
            return true;

            return false;

        }
    }
}

Find no of square between two numbers in c#.

   /* Watson gives two integers(A and B ) to Sherlock and asks if he can count the number of square integers between A and B(both inclusive).

Note: A square integer is an integer which is the square of any integer.For example, 1, 4, 9, and 16 are some of the square integers as they are squares of 1, 2, 3, and 4, respectively.
Input Format
The first line contains T, the number of test cases. T test cases follow, each in a new line.
Each test case contains two space-separated integers denoting A and B.
Constraints
1<=T<=100
1<=A<=B<=10^9


Output Format

For each test case, print the required answer in a new line.
Sample Input
2
3 9
17 24
Sample Output
2
0
Explanation
Test Case #00: In range[3,9] ,4  and 9 are the two square numbers.
Test Case #01: In range [17 24], there are no square numbers.*/


using System;
using System.Linq;

namespace HackerDemo
{

   public class NoOFSquareNumbers
    {
        public void GetnoOfSquareNumber()
        {
            Console.WriteLine("Enter no of test case is required");
            int t = Convert.ToInt32(Console.ReadLine());
            for (int a0 = 0; a0 < t; a0++)
            {
                 Console.WriteLine("Enter first two numbers");
                string line = Console.ReadLine();
                string[] tokens = line.Split(' ');
                int[] numbers = Array.ConvertAll(tokens, int.Parse);
                int fn = 0, sn = 0;
                if (numbers.Count() == 2)
                {
                    fn = numbers[0];
                    sn = numbers[1];
                }
                int count = 0, gn = fn > sn ? fn : sn;

                for (int i = fn < sn ? fn : sn; i <= gn; i++)
                {
                    if (isSquareNumber(i))
                    {
                        count++;
                    }
                }
                Console.WriteLine(count);
            }
        }

        private bool isSquareNumber(int n)
        {
            double result = Math.Sqrt(n);
            return result % 1 == 0;
        }
    }
}

Number divisible by no of digit of the same number.

/* Given an integer,N, traverse its digits(d1,d2,..., dn) and determine how many digits evenly divide N(i.e.: count the number of times N divided by each digit di has a remainder of 0). Print the number of evenly divisible digits.

      Note: Each digit is considered to be unique, so each occurrence of the same evenly divisible digit should be counted(i.e.: for N=111 , the answer is 3).
      Input Format
      The first line is an integer, T, indicating the number of test cases.
      The T subsequent lines each contain an integer, N .
      Constraints
      1<=T<=15
      0<=N<=10^9
      Output Format
      For every test case, count and print(on a new line) the number of digits in N that are able to evenly divide N.
      Sample Input
      2
      12
      1012
      Sample Output
      2
      3
      Explanation
      The number 12  is broken into two digits,1 and 2. When 12 is divided by either of those digits, the calculation's remainder is 0 ; thus, the number of evenly-divisible digits in 12 is 2 .
      The number 1012 is broken into four digits ,1 , 0, 1, and 2. 1012 is evenly divisible by its digits 1, 1, and 2, but it is not divisible by 0 as 1012 division by zero is undefined; thus, our count of evenly divisible digits 1012 is 3 .

    */



   public class FindDigit
    {
        public void GetnoOfDigit()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int a0 = 0; a0 < t; a0++)
            {
                int n = Convert.ToInt32(Console.ReadLine());
                int temp = n, count=0;
                while (temp > 0)
                {
                 
                    int d = temp % 10;
                    if (isNumberDivisiblebyDigit(n, d))
                    {
                        count++;
                    }
                    temp = temp / 10;
                }

                Console.WriteLine(count);
            }
        }

        private bool isNumberDivisiblebyDigit(int n, int d)
        {
            return d==0 || n==d? false:n % d == 0;
        }


    }
}