Skip to content

Instantly share code, notes, and snippets.

View ironpython2001's full-sized avatar

Sunil P ironpython2001

  • OSI Digital
  • Hyderabad
View GitHub Profile
@ironpython2001
ironpython2001 / longestpalindromesubstring.cs
Last active April 29, 2022 09:51
Given a string s, return the longest palindromic substring in s. using C# and Dotnet
/*
Given a string s, return the longest palindromic substring in s.
Example 1:
Input: s = "babad"
Output: "bab"
Explanation: "aba" is also a valid answer.
Example 2:
Input: s = "cbbd"
Output: "bb"
*/
@ironpython2001
ironpython2001 / joinlistofstringswithdelimeter.cs
Created April 29, 2022 13:59
C# join list of strings with delimeter
/*
Input : [“hello”, “world”, “message”]
Separator: “ +++ ”
Result: “hello +++ world +++ message”
*/
using System;
using System.Collections.Generic;
var input = new List<string>{"hello","world","message"};
@ironpython2001
ironpython2001 / checkwellformedbracing.cs
Last active May 2, 2022 13:48
check well formed bracing in c#
/*
check wellformedbracing
Input Result Comment
“(( ))” True
“( )( )” True
“(( )))((( ))” False Although it has the same amount of opening and closing braces,
it is not properly nested
“((( )” False No suitable bracing
@ironpython2001
ironpython2001 / versionnocomp.cs
Last active May 5, 2022 08:04
version number comparison in c#
//Version 1 Version 2 Result
//1.11.17 2.3.5 2.3.5
//2.1 2.1.3 2.1.3
//2.3.5 2.4 2.4.0
//3.1 2.4 3.1.0
//3.3 3.2.9 3.3.0
//7.2.71 7.2.71 7.2.71
string s1 = "2.1";
@ironpython2001
ironpython2001 / evenbeforeoddnos.cs
Created May 6, 2022 08:36
even before odd numbers in c#
//even before odd numbers
//Input Result
//[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] [2, 4, 6, 8, 10, 3, 7, 1, 9, 5]
//[2, 4, 6, 1, 8] [2, 4, 6, 8, 1]
//[2, 4, 6, 8, 1] [2, 4, 6, 8, 1]
var lst = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var lstEven = new List<int>();
var lstOdd = new List<int>();
@ironpython2001
ironpython2001 / palindromelists.cs
Created May 6, 2022 08:56
palindrome lists in c#
//Palindrome Lists
//Input Result
//[“One”, “Test”, “ – ”, “Test”, “One”] True
//[“Max”, “Mike”, “Mike”, “Max”] True
//[“Tim”, “Tom”, “Mike”, “Max”] False
//var lst = new List<string>() { "One", "Test", "–", "Test", "One" };
var lst = new List<string>() { "Max", "Mike", "Mike", "Max"};
var cnt = lst.Count()/2;
@ironpython2001
ironpython2001 / addonetoarrayasno.cs
Last active May 13, 2022 07:41
Add One to an Array as a Number in c#
//Add One to an Array as a Number
//Input Result
//[1, 3, 2, 4] [1, 3, 2, 5]
//[1, 4, 8, 9] [1, 4, 9, 0]
//[9, 9, 9, 9] [1, 0, 0, 0, 0]
var lst = new List<int> { 1, 4, 8, 9 };
var one = 1;
var revlst = lst.ToArray().Reverse().ToList();
@ironpython2001
ironpython2001 / arraysplitwithrefelement.cs
Created May 6, 2022 10:47
Array Split with reference element in c#
//Desc: Array Split
//Say you have an array (or list) of arbitrary integers.
//The data structure must be reordered so that all values less than a
//special reference value are placed on the left. All values greater than
//or equal to the reference value are placed on the right.
//The ordering within the subranges is not relevant and may vary.
//Input Reference element Sample result
//[4, 7, 1, 20] 9 [1, 4, 7, 9, 20]
//[3, 5, 2] 7 [2, 3, 5, 7]
git rev-parse --abbrev-ref HEAD
or with Git 2.22 and above:
git branch --show-current
Refernce: https://stackoverflow.com/questions/1146973/how-do-i-revert-all-local-changes-in-git-managed-project-to-previous-state
#!/bin/sh
git reset --hard
git clean -f -d
git checkout HEAD