Skip to content

Instantly share code, notes, and snippets.

View P-A-R-U-S's full-sized avatar
💭
Building a dream...

Valentyn Ponomarenko P-A-R-U-S

💭
Building a dream...
View GitHub Profile
@P-A-R-U-S
P-A-R-U-S / Rotational_Cipher.go
Last active June 18, 2020 07:21
Facebook: Rotational Cipher
package main
import (
"fmt"
)
func rotationalCipher(input string, rotationFactor int) string {
b := []uint8(input)
for i:=0; i < len(input); i++ {
@P-A-R-U-S
P-A-R-U-S / Contiguous_Subarrays.go
Created June 18, 2020 05:57
Facebook: Contiguous Subarrays
package Facebook
import "testing"
/*
Contiguous Subarrays
You are given an array a of N integers. For each index i, you are required to determine the number of contiguous
subarrays that fulfills the following conditions:
The value at index i must be the maximum element in the contiguous subarrays, and
@P-A-R-U-S
P-A-R-U-S / Passing_Yearbooks.go
Last active March 13, 2023 17:48
Facebook: Passing Yearbooks
package Facebook
import "testing"
/*
Passing Yearbooks
There are n students, numbered from 1 to n, each with their own yearbook.
They would like to pass their yearbooks around and get them signed by other students.
You're given a list of n integers arr[1..n], which is guaranteed to be a permutation of 1..n
@P-A-R-U-S
P-A-R-U-S / Cracking_the_Coding_Interview_5-3_test.go
Created June 16, 2020 06:22
Flip Bit to Win: Flip one bit to get longest sequence of 1s
package Part_5
import (
"testing"
)
/*
Flip Bit to Win: You have an integer and you can flip exactly one bit from a 13 to a 1.Write code to find the length of
the longest sequence of ls you could create.
@P-A-R-U-S
P-A-R-U-S / Cracking_the_Coding_Interview_5-1_test.go
Last active June 15, 2020 07:50
Insertion M into N from bit "i" to "j"
package Part_5
import "testing"
/*
Insertion: You are given two 32-bit numbers, N and M, and two bit positions, i and j.
Write a method to insert M into N such that M starts at bit j and ends at bit i.
You can assume that the bits j through i have enough space to fit all of M.
That is, if M= 10011, you can assume that there are at least 5 bits between j and i.
You would not, for example, have j = 3 and i = 2, because M could not fully fit between bit 3 and bit 2.
@P-A-R-U-S
P-A-R-U-S / Cracking_the_Coding_Interview_4-11_test.go
Created June 15, 2020 04:28
Cracking the Coding Interview - Task - 4.11 - Random Node, Insert Node, Delete Node
package Part_4
import (
"fmt"
"math/rand"
"testing"
"time"
)
/*
@P-A-R-U-S
P-A-R-U-S / Cracking_the_Coding_Interview_4-12_test.go
Last active June 15, 2020 03:55
Cracking the Coding Interview - Task - 4.12 - Find path equal K in binary tree
package Part_4
import (
"testing"
)
/*
Paths with Sum: You are given a binary tree in which each node contains an integer value (which might be positive or negative).
Design an algorithm to count the number of paths that sum to a given value.
@P-A-R-U-S
P-A-R-U-S / Cracking_the_Coding_Interview_4-9_test.go
Last active June 1, 2020 02:30
Cracking the Coding Interview - Task - 4.9
package Part_4
import (
"fmt"
"testing"
)
/*
BST Sequences: A binary search tree was created by traversing through an array from left to right and inserting each element.
Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.
@P-A-R-U-S
P-A-R-U-S / Cracking_the_Coding_Interview_4-8_test.go
Last active May 31, 2020 21:46
Cracking the Coding Interview - Task - 4.8
/*
First Common Ancestor: Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree.
Avoid storing additional nodes in a data structure.
NOTE: This is not necessarily a binary search tree.
Hints: # 10, #16, #28, #36, #46, #70, #80, #96
*/
/*
Создайте алгоритм и напишите код поиска первого общего предка двух узлов бинарного дерева. Постарайтесь избежать
хранения дополнительных узлов в структуре данных.
@P-A-R-U-S
P-A-R-U-S / Find_max_number_of_connected_colors_in_grid.go
Last active December 27, 2019 18:11
Find max number of connected colors in grid
package Google
import "testing"
// Find max number of connected colors in grid
// https://proglib.io/p/google-interview-task/?fbclid=IwAR2PXn_XqXQx97U3FLSFssVfDa1-m2P-T3yAJELEJoOWpNfcQjfyesOegpY
type si struct {
r int
c int