Skip to content

Instantly share code, notes, and snippets.

View Youngestdev's full-sized avatar
💭
I may be slow to respond.

Abdulazeez Abdulazeez Adeshina Youngestdev

💭
I may be slow to respond.
View GitHub Profile

1. Reformat Date

Given a date string in the form Day Month Year, where:

Day is in the set {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}. Month is in the set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}. Year is in the range [1900, 2100]. Convert the date string to the format YYYY-MM-DD, where:

YYYY denotes the 4 digit year.

Question One.

Find the sum of the first n numbers.. where 1 < n > 1000000.

Question Two.

Given a string of length n consisting of digits [0-9], count the number of ways the given string can be split into prime numbers, each of which is in the range 2 to 100 inclusive. Since the answer can be large, return the answer modulo 10e9 + 7. Note: A partition that contains numbers with leading zeroes will be invalid and the initial string does not contain leading zeroes. Take for example the input string to be s = "11373", then this string can be split into 6 different ways as [11, 37, 3), [113, 7, 3), [11, 3, 73), [11, 37, 3), (113, 73) and [11, 373) where each one of them contains only prime numbers.

s = "11373"
[[11, 37, 3], [113, 7, 3], [11,3,73], [113, 73], [11. 373]]
def deletion_distance(str1, str2):
@lru_cache(None)
def recursiveHelper(str3, str4):
if not str4 or not str3: return ''
idx = str3.find(str4[0])
store = (str4[0] + recursiveHelper(str3[idx+1:], str4[1:])) if idx != -1 else ''
return store if idx == 0 else max(store, recursiveHelper(str3, str4[1:]), key=len)
return len(str1) + len(str2) - 2*len(recursiveHelper(str1, str2))
@Youngestdev
Youngestdev / N-Queens.py
Created June 11, 2020 23:09
Generating N-Queens possible solution sturvs.
def placequeens(arr, r):
n = len(arr)
res = []
if r == n:
# Print solutions
print(arr)
else:
for j in range(0, n):
legal = True
for i in range(0, r):
class WeightedGraph:
pass
def DFS(self, i, visited):
v = self.graph[v]
idx = self.graph.index(v)
visited[idx] = True
print(v, end="")
for i in v:
if not visited[i]:
class Solution {
public:
int uniquePaths(int m, int n) {
int dp[n][m];
dp[0][0] = 1;
if (m == 0 || n == 0) {
return 0;
}
for(int i = 0; i < n; i++) {
dp[i][0] = 1;
@Youngestdev
Youngestdev / Allocation.py
Created April 17, 2020 15:39
Google Kickstart
T = int(input())
count = 0
f = 0
if T is None or T is 0:
pass
while f < T:
count += 1
@Youngestdev
Youngestdev / mock-interview.md
Created November 23, 2019 17:48
Leetcode mock interview 1.

1

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones.

Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap.

Example:


Input: 4
Output: false 
@Youngestdev
Youngestdev / twoSums.go
Created October 19, 2019 23:36
Function to add two numbers in a given array to match a target. It's a slow solution.
func twoSum(nums []int, target int) []int {
var res []int
for i := 0; i < len(nums); i++ {
for j := 0; j < i; j++ {
if nums[i] + nums[j] == target {
res = append(res, i)
res = append(res, j)
break
}
}
@Youngestdev
Youngestdev / Frontend Masters Algo exercise.js
Created October 16, 2019 08:28
Frontend masters algorithm course exercise.
// Task 1: Write a function, times10, that takes an argument, n, and multiples n times 10
// a simple multiplication fn
const times10 = (n) => {
return n * 10
};
console.log('~~~~~~~~~~~~~~TASK 1~~~~~~~~~~~~~~');
console.log('times10 returns:', times10(9));
// Task 2: Use an object to cache the results of your times10 function.