This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Question: | |
Given a string s, find the length of the longest substring without repeating characters. | |
Solution: | |
using sliding window technique and hash map. | |
Window Sliding Technique is a computational technique that aims to reduce the use of nested loops and replace it with a single loop, thereby reducing the time complexity. | |
steps: | |
1. Initialize two pointers, 'start' and 'end,' both pointing to the start of the string. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Question: | |
Given an integer array nums, find the subarraywith the largest sum, and return its sum. | |
Steps: | |
i'll be exxplaining this using Kadane’s Algorithm. | |
Kadane’s Algorithm is an iterative dynamic programming algorithm. It calculates the maximum sum subarray ending at a particular position by using the maximum sum subarray ending at the previous position. Follow the below steps to solve the problem. | |
1. Define two-variable currSum which stores maximum sum ending here and maxSum which stores maximum sum so far. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: | |
Imagine a robot standing at position (0,0) in a 2D grid, given a string consisting of its moves, find the | |
final location of the robot | |
Type of parameters passed | |
U: up, INCREASE in the y-axis | |
D: down, DECREASE in the y axis | |
R: right, INCREASE in the x-axis | |
L: left, DECREASE in the x-axis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: | |
Given two input strings, in a form of binary numbers. Our job is to add them togeth and simply return their sum | |
BINNARY NUMBERS: | |
Binary number are numbers that represent only by zero (0) and one (1) | |
DECIMAL NUMBERS: | |
Decimal numbers are constructed by digit base in columns that are multiple of 10. for example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: | |
Given a non-empty array of integers, every element appears twice except one, find it | |
Steps: | |
1. Find the sum of the array | |
2. Find a unique element in the array | |
3. Find the sum of the unique element | |
4. Multiply the sum of the unique element by 2 | |
5. then minus sum of the array from the result of step 4 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: | |
Count the number of prime numbers less than a non-negative given number (N) | |
What is a prime Number: | |
Any number that's greater than one (1) and non - divisible by anything except One(1) and itself | |
Steps: | |
1. Define a boolean array of size n and set all element to True except index 0 and 1 | |
e.g: n = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
class Solution: | |
def getLeftPosition(self, nums, target): | |
left = 0 | |
right = len(nums) - 1 | |
while left <= right: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
var nums = []int{5, 7, 7, 8, 8, 10} | |
var target = 8 | |
var result = searchRange(nums, target) | |
fmt.Println(result) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mask_phone_number(phone_number): | |
formatted_num = "234" + phone_number[-10:] | |
first_covered = formatted_num[0:5] | |
second_covered = formatted_num[-3:] | |
total_covered = first_covered + "*****" + second_covered | |
return total_covered | |
print(mask_phone_number("09098012398")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
import random | |
def generate_random_name(length): | |
VOWELS = "aeiou" | |
CONSONANTS = "".join(set(string.ascii_lowercase) - set(VOWELS)) | |
word = "" | |
for i in range(length): | |
if i % 2 == 0: |
NewerOlder