Athena Health Interview Question
Applications DevelopersCountry: India
Interview Type: In-Person
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Collections;
using System.Text.RegularExpressions;
namespace Anagram
{
class Program
{
/* program to test above function */
public static void Main()
{
//Convert Character into string
char[] ch1 = new char[5] { 'H', 'e', 'l', 'l', 'o' };
string ss = new string(ch1);
Console.WriteLine(ss);
//----------*******************-----------------
string str = "my brother is taller than me@1233334. I always a short man,but smaller than him.";
//Count a particular character in a string
int numberofE = str.ToCharArray().Count(c => c == 'e');
int numberofWord = str.ToCharArray().Count(c => c == ' ');
int numberofSentence= str.ToCharArray().Count(c => c == '.');
Console.WriteLine("Number of E in the given sentence is : " + numberofE);
Console.WriteLine("Number of word in the given sentence is : " + numberofWord);
Console.WriteLine("Number of sentence in the given string is : " + numberofSentence);
//Number of occurece of each character in a given string
int numberofoccur = 0;
Dictionary<char, int> dc = new Dictionary<char, int>();
char[] newarr = str.ToCharArray();
foreach (char ch in newarr)
{
numberofoccur = str.ToCharArray().Count(c => c == ch);
if (numberofoccur > 1)
{
if (!dc.ContainsKey(ch))
{
dc.Add(ch, numberofoccur);
Console.WriteLine("The character " + ch + " Repeated upto " + numberofoccur + " times");
}
}
}
//----------*******************-----------------
//Extract Number from string - Option1
string intextract =string.Empty;
for (int i = 0; i < str.Length; i++)
{
if (char.IsDigit(str[i]))
{
intextract += str[i];
}
}
//----------*******************-----------------
//Extract Number from string - Option2
string intextract1 = Regex.Match(intextract, @"\d+").Value;
int a = int.Parse(intextract);
int b = int.Parse(intextract1);
Console.WriteLine("The Extracted numbers are : " + a);
Console.WriteLine("The Extracted numbers are : " + b);
//----------*******************-----------------
//Find the largest word in a sentence
string BigWord = string.Empty;
int maxcount = 0;
foreach (string word in str.Split(' '))
{
if (word.Length > maxcount)
{
BigWord = word;
maxcount = word.Length;
}
}
Console.WriteLine("Longest word in the sentence is : " + BigWord + "and the length of the word is : " + maxcount);
//----------*******************-----------------
//remove space in the word
str = str.Replace(" ", "");
Console.WriteLine("After remove the space in the sentence " + str);
//----------*******************-----------------
Console.ReadLine();
}
}
}
//remove space in the word
- Anonymous March 07, 2020str = str.Replace(" ", "");
Console.WriteLine("After remove the space in the sentence " + str);
//----------*******************-----------------
//Find the largest word in a sentence
string BigWord = string.Empty;
int maxcount = 0;
foreach (string word in str.Split(' '))
{
if (word.Length > maxcount)
{
BigWord = word;
maxcount = word.Length;
}
}
Console.WriteLine("Longest word in the sentence is : " + BigWord + "and the length of the word is : " + maxcount);
//----------*******************-----------------
//Find the count of E
int numberofE = str.ToCharArray().Count(c => c == 'e');
//Extract Number from string - Option1
string intextract =string.Empty;
for (int i = 0; i < str.Length; i++)
{
if (char.IsDigit(str[i]))
{
intextract += str[i];
}
}
//----------*******************-----------------
//Extract Number from string - Option2
string intextract1 = Regex.Match(intextract, @"\d+").Value;
int a = int.Parse(intextract);
int b = int.Parse(intextract1);
Console.WriteLine("The Extracted numbers are : " + a);
Console.WriteLine("The Extracted numbers are : " + b);
//----------*******************-----------------
int numberofWord = str.ToCharArray().Count(c => c == ' ');
int numberofSentence= str.ToCharArray().Count(c => c == '.');