Posts

Showing posts from July, 2020

Algorithm : Longest Substring Without Repeating Characters

    Algorithm : Longest Substring Without Repeating Characters Problem Statement: Given a string, find the length of the  longest substring  without repeating characters.  This question can be found in leetcode #3.      Example: if the input string is "sreenath", then the output should be: 5      Reason\Explanation:  sre - First three characters, until the next e.  - 3 re. -   we move the next substring which is re until  - 2 since no words can be formed using starting with ee. -0  enath   -  with no repeating characters. - 5      As you can see that the maximum number of characters is 5.       Logic:     Sliding Window Technique:          We have a window just like how you have a Window at home, if you want to open the window fully,       you basically slide the window to the fullest. If you have t...

Python- Binary Search(Recursive and Iterative)

          Binary Search(Recursive and Iterative) in Python I am recently venturing into Python Language. Learning and comparing them with C# Skills I already possess.  Here's my first code in Python where I will discuss about Binary Search using Iterative and Recursive Approach.  As we know, Binary Search is one of the algorithm where user can search for an item in  O(1) - Best Case  O(log n)- Average Case  Binary Search is based on Divide and Conquer Strategy. Basic Concept of Binary Search. :       1)  You have a low index      2)  You have a high index.      3)  We calculate the mid value(initially: mid=low+high/2) and then depending on the whether the key that we are searching for is lesser than low or greater than high, we change the low and high values accordingly.      4) If the Key Value is less than Mid, we set high=mid-1;     5) If the key...