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 / Golang-IP-to-CIDR
Created March 16, 2018 22:53
Go: Convert IP to CIDR
/ Convert IPv4 range into CIDR
func iPv4RangeToCIDRRange(ipStart string, ipEnd string) (cidrs []string, err error) {
cidr2mask := []uint32{
0x00000000, 0x80000000, 0xC0000000,
0xE0000000, 0xF0000000, 0xF8000000,
0xFC000000, 0xFE000000, 0xFF000000,
0xFF800000, 0xFFC00000, 0xFFE00000,
0xFFF00000, 0xFFF80000, 0xFFFC0000,
0xFFFE0000, 0xFFFF0000, 0xFFFF8000,
@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 / Golang-CIDR-to-IP
Created March 16, 2018 22:55
Go: Convert CIDR to IP
// Convert CIDR to IPv4 range
func CIDRRangeToIPv4Range(cidrs []string) (ipStart string, ipEnd string, err error) {
var ip uint32 // ip address
var ipS uint32 // Start IP address range
var ipE uint32 // End IP address range
for _, CIDR := range cidrs {
@P-A-R-U-S
P-A-R-U-S / ReverseLinkedList.go
Created May 20, 2019 23:54
Reverse Linked List in Go/Golang
package Helpers
import (
"testing"
)
type Node struct {
data interface{}
prev *Node
}
@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 / 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 / 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.