Implementing the various data basic structures starting from hash tables, stacks and queues to binary tree and others. Basic search and sort algorithms in python : binary search , quick sort , bubble sort , merge sort, insertion sort.
Solving some prgoramming problems in the leetcode website.ss
Given the root of a binary tree, return the sum of every tree node's tilt.
The tilt of a tree node is the absolute difference between the sum of all left subtree node values and all right subtree node values. If a node does not have a left child, then the sum of the left subtree node values is treated as 0. The rule is similar if the node does not have a right child.
Input: root = [1,2,3] Output: 1. Explanation: Tilt of node 2 : |0-0| = 0 (no children) Tilt of node 3 : |0-0| = 0 (no children) Tilt of node 1 : |2-3| = 1 (left subtree is just left child, so sum is 2; right subtree is just right child, so sum is 3) Sum of every tilt : 0 + 0 + 1 = 1
Given an array of integers nums and an integer target, return indices of tsshe two numbers such that they add up to target.
Input: nums = [2,7,11,15], target = 9. Output: [0,1] Output: Because nums[0] + nums[1] == 9, we return [0, 1].
Given a string s, find the length of the longest substring without repeating characters.
Example 1:
Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3.
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays
The overall run time complexity should be O(log (m+n)). Example 1:
Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and median is 2.
Example 2:
Input: nums1 = [1,2], nums2 = [3,4] Output: 2.50000 Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.