development

Longest Substring without Repeating Characters

The solution uses a sliding window and uses O(n) time and O(n) space. There are many cases to take care of. We can skip the process string less than size 2. Iterate the string, checking each char as key in the hash, adding if not present. If not present in hash, add each char as […]

Read more
development

vscode: How to Customize a Settings and Theme

You can change almost everything in vscode settings. I wasn’t happy with terminal settings, so found very useful hints on changing them. My current settings.json is as follows: { “telemetry.enableTelemetry”: false, “telemetry.enableCrashReporter”: false, “editor.renderWhitespace”: “all”, “editor.wordWrap”: “on”, “editor.fontLigatures”: true, “editor.fontFamily”: “‘Hack'”, “editor.minimap.enabled”: false, “breadcrumbs.enabled”: false, “files.autoSave”: “afterDelay”, “workbench.statusBar.visible”: true, “workbench.activityBar.visible”: true, “git.autofetch”: true, “python.jediEnabled”: false, […]

Read more
development

Rapid Learn Swagger OpenAPI

What is Swagger? A standard way to document REST APIs The documentation is described in a YAML or JSON document. OpenAPI has syntax and tags to write an API description. Why Use Swagger? Very standard It not just describes APIs but also serves as an APIs contract among teams. Each API specifies the expected request, […]

Read more
development

Adding Two Numbers in LinkedList

# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def addTwoNumbers(self, l1, l2): “”” :type l1: ListNode :type l2: ListNode :rtype: ListNode “”” head1, head2 = l1, l2 head3 = None last = head3 carry = 0 while head1 and head2: dsum […]

Read more
development

Palindrome String Check With Non-alphanumeric Characters

class Solution(object): def isPalindrome(self, s): “”” :type s: str :rtype: bool “”” if len(s) < 1: return True start, end = 0, len(s) – 1 while start < end: # Loop till a special char is found while start < end and not s[start].isalnum(): start += 1 # Always keep the check start < end […]

Read more
development

Stocks Maximize Profit, Multiple Buy & Sell

class Solution(object): def maxProfit(self, prices): “”” :type prices: List[int] :rtype: int “”” if len(prices) < 2: return 0 minP = prices[0] result = 0 for price in prices: if minP == float(‘inf’): minP = price profit = (price – minP) if profit > 0: result += profit minP = float(‘inf’) minP = min(price, minP) return […]

Read more
development

Stock Buy-Sell Maximize Profit

class Solution(object): def maxProfit(self, prices): “”” :type prices: List[int] :rtype: int “”” if len(prices) == 0 or len(prices) == 1: return 0 minP = prices[0] result = 0 for price in prices: # Maintain the maximum profit at each price result = max(result, price – minP) # Maintain the minimum price seen so far minP […]

Read more