Skip to content

Instantly share code, notes, and snippets.

@schauhan232
schauhan232 / HttpClientExtensions.cs
Last active March 21, 2023 11:06
Http Extension methods/Http Helper to get Response/ Request serialized and detribalized
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@schauhan232
schauhan232 / HackerRank Day 1 - C# "Data Types"
Last active July 5, 2021 13:14
HackerRank Day 1 - C# "Data Types"
using System;
using System.Collections.Generic;
using System.IO;
class Solution {
static void Main(String[] args) {
int i = 4;
double d = 4.0;
string s = "HackerRank ";
@schauhan232
schauhan232 / Grading Students
Created July 6, 2021 09:59
HackerRank Grading Students
/*
* Complete the 'gradingStudents' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts INTEGER_ARRAY grades as parameter.
*/
public static List<int> gradingStudents(List<int> grades)
{
return grades.Select(grade=>{
@schauhan232
schauhan232 / Check if a key is present in every segment of size k in an array
Created July 6, 2021 10:44
GeeksForGeeks - Check if a key is present in every segment of size k in an array C#
class Program
{
public static void Main(string[] args)
{
int[] userInputArray = { 21, 23, 56, 65, 34, 54, 76, 32, 23, 45, 21, 23, 25 } ;
int userAskedNumberToBeFind = 23;
int segment = 5;
var output = "NO";
@schauhan232
schauhan232 / Minimum and Miximum from given array
Created July 6, 2021 11:52
GeeksForGeeks: Program to find the minimum and maximum element of an array
class Program
{
public static void Main(string[] args)
{
int[] userInputArray = { 12, 1234, 45, 67, 1 };
Console.WriteLine(MinimumValue(userInputArray));
Console.WriteLine(MaximumValue(userInputArray));
Console.Read();
}
@schauhan232
schauhan232 / Find Maximum and Second Maximum with Minimum and Second Minimum value from array
Created July 7, 2021 03:28
GeeksForGeeks: Find Maximum and Second Maximum with Minimum and Second Minimum value from array
class Program
{
public static void Main(string[] args)
{
int[] userInputArray = { 104, 5, 99, 100, 45, 102, 67, 1, 3, 2, 9, 105 };
var (minimum, secondMinimum) = MinimumValue(userInputArray);
var (maximum, secondMaximum) = MaximumValue(userInputArray);
Console.WriteLine($"Minimum: {minimum}, Second Minimum {secondMinimum}");
@schauhan232
schauhan232 / Day 2 : Operators
Created July 7, 2021 04:05
Hackerrank : Day 2 : Operators
public static void solve(double meal_cost, int tip_percent, int tax_percent)
{
double tip = (meal_cost /100) * tip_percent;
double tax = (meal_cost / 100) * tax_percent;
double total_cost = meal_cost + tip + tax;
Console.WriteLine(Math.Round(total_cost));
}
@schauhan232
schauhan232 / Trapping Rain Water
Created July 7, 2021 08:34
GeeksForGeeks: Trapping Rain Water
public class Solution {
public int Trap(int[] height) {
return GetTotal(height);
}
private static int GetTotal(int[] height)
{
var totalLength = height.Length;
var total = 0;
for (int i = 0; i < totalLength; i++)
@schauhan232
schauhan232 / Counting Sort Hackerrank
Created July 9, 2021 14:10
Hackerrank: Counting Sort 2 C#
//Learned theory from https://www.youtube.com/watch?v=HkvChUv9dDg
class Program
{
public static void Main(string[] args)
{
var array = new int[] { 19, 10, 12, 10, 24, 25, 22 };
//generate empty array to add values on index
// keeping +1 in max to avoid index out error can be handle by other condition though
var arrayForOutPut = Enumerable.Repeat(0, array.Max() + 1).ToList();
@schauhan232
schauhan232 / Remove Duplicate Element from Sorted Array c#
Created July 10, 2021 05:34
Remove duplicate element from Sorted Array C#
class Program
{
public static void Main(string[] args)
{
var array = new int[] { 0, 0, 1, 1, 1, 2, 2, 3, 3, 4 }; // 1, 1, 2
var LEFT = 0;
var RIGHT = 1;
var newIndex = 1;