Posts

Showing posts from January, 2018

Participated in a LeetCode contest, did the question #771-Sliding Puzzle

Finished the code in 2.50 hours, the allocated time was 1.50hrs. Any the code seems to missed the performance target, timed out in some test cases:( Yikes

Not added in as a Leetcode problem but for sure was used by some company before

https://discuss.leetcode.com/topic/59889/dice-roll/3 http://www.mathpages.com/home/kmath093/kmath093.htm When n dices with m faces are rolled together, find the number of ways the sum of the faces is X. second link above showed a way to reduce the loops from 3 to 2!

Worked on the Leetcode #179 - Largest Number

https://leetcode.com/problems/largest-number/description/ Solved this on using the IComparable Interface. public class Solution {     public string LargestNumber(int[] nums) {               List<NumericString> list = new List<NumericString>();         for(int i=0; i<nums.Length;i++)         {              list.Add(new NumericString(nums[i]));         }         list.Sort();//sort ascending         //list.Reverse();               StringBuilder builder = new StringBuilder();         foreach (NumericString item in list)         {            builder.Append(item.StringValue);         }               String temp = builder.To...

Worked on the Hanoi Tower problem which actually too simple to be in the Leetcode questions

Completed question 46 - permutations

https://leetcode.com/problems/permutations/description/ using System; using System.Collections; using System.Collections.Generic; public class Solution {     public int itemCount { get; set; }     public List<int> originalArray { get; set; }     public List<IList<int>> arrayPermutations { get; set; }        public IList<IList<int>> Permute(int[] nums) {         itemCount=nums.Length;         originalArray=new List<int>();         for (int i=0; i<itemCount;i++)         {             originalArray.Add(nums[i]);         }          arrayPermutations = new List<IList<int>>();         GeneratePermuatation(originalArray, new List<int>(), 0);         return (IList<IList<i...

Worked on the question #72-Edit Distance

https://leetcode.com/problems/edit-distance/description/ First tried the recursion based simple Edit Distance solution, it timed up on test case: "dinitrophenylhydrazine" "benzalphenylhydrazone" Then I had to rely on an implementation of the standard Levenshtein Algorithm to beat the clock.

Starting to play LeetCode today - question 151

Starting with question 151: https://leetcode.com/problems/reverse-words-in-a-string/description/ Given an input string, reverse the string word by word. For example, Given s = " the sky is blue ", return " blue is sky the ". Update (2015-02-12): For C programmers: Try to solve it  in-place  in  O (1) space. My answer: using System; using System.Text; public class Solution {     public string ReverseWords(String s) {     String s2=reverseString(s);     var chars2=s2.ToCharArray();         var words=s2.Split(null);     StringBuilder wordBuffer=new StringBuilder();         foreach(String word in words)         {              if(!String.IsNullOrEmpty(word))              {                   wordBuffer.Append(reverseString(word));...