Skip to content

Instantly share code, notes, and snippets.

@schauhan232
schauhan232 / Create next smallest number from the same array element
Created July 12, 2021 10:56
Create next smallest number from the same array element
class Program
{
public static void Main(string[] args)
{
var matrix = new int[] { 2, 5, 8, 7, 6, 1 };
var loopLength = matrix.Length - 1;
var firstSmallElementIndex = -1;
//1. Find the index where there's small element on left hand side
@schauhan232
schauhan232 / Minimum Number of platform needed
Created July 12, 2021 12:34
Minimum Number of platform needed
class Program
{
public static void Main(string[] args)
{
var arrival = new int[] { 900, 940, 950, 1100, 1500, 1800 };
var departure = new int[] { 910, 1200, 1120, 1130, 1900, 2000 };
Array.Sort(arrival);
Array.Sort(departure);
@schauhan232
schauhan232 / Distribute Candy Problem
Last active July 15, 2021 07:19
Distribute Candy Problem
There are N children standing in a line with some rating value. You want to distribute a minimum number of candies to these children such that:
Each child must have at least one candy.
The children with higher ratings will have more candies than their neighbors.
You need to write a program to calculate the minimum candies you must give.
class Program
{
public static void Main(string[] args)
@schauhan232
schauhan232 / Print diagonal matrix
Last active July 15, 2021 07:20
C# Print Diagonal matrix
using System;
namespace ConsoleApp1
{
class Program
{
public static void Main(string[] args)
{
var matrix = new int[,] {
{ 1, 2, 3, 4,5},
@schauhan232
schauhan232 / C# Count frequncies of elements in array
Last active July 15, 2021 09:45
C# Count frequncies of elements in array
Array of length n having integers 1 to n with some elements being repeated.
Count frequencies of all elements from 1 to n in Time Complexity O(n) and Space Complexity O(1)
class Program
{
public static void Main(string[] args)
{
var matrix = new int[] { 5, 2, 7, 7, 5, 5, 2 };
var someUniqueNumberGreaterThan = matrix.Max() + 1;