Skip to content

Instantly share code, notes, and snippets.

View Josephchinedu's full-sized avatar
🔥
building

Devjoseph Josephchinedu

🔥
building
View GitHub Profile
@Josephchinedu
Josephchinedu / longest_substring_without_ repeating_characters.text
Last active May 31, 2023 19:09
Longest Substring Without Repeating 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.
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.
@Josephchinedu
Josephchinedu / index.py
Created September 22, 2022 01:08
Robot return to origin
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
@Josephchinedu
Josephchinedu / index.py
Created September 22, 2022 00:45
add binary
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
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
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
@Josephchinedu
Josephchinedu / app.py
Created September 7, 2022 23:38
FIND THE FIRST AND LAST ELEMENT IN A SORTED ARRAY
from typing import List
class Solution:
def getLeftPosition(self, nums, target):
left = 0
right = len(nums) - 1
while left <= right:
@Josephchinedu
Josephchinedu / main.go
Last active September 8, 2022 11:10
FIND THE FIRST AND LAST ELEMENT IN A SORTED ARRAY
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)
}
@Josephchinedu
Josephchinedu / mask_phone_number.py
Last active August 24, 2022 16:21
Mask Phone Number
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"))
@Josephchinedu
Josephchinedu / full_name.py
Created August 24, 2022 15:51
Generate random name
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: