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
/ 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, |
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 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 |
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
// 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 { |
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 Helpers | |
import ( | |
"testing" | |
) | |
type Node struct { | |
data interface{} | |
prev *Node | |
} |
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 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 |
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 rotationalCipher(input string, rotationFactor int) string { | |
b := []uint8(input) | |
for i:=0; i < len(input); i++ { |
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 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. |
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 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. |
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 Part_4 | |
import ( | |
"fmt" | |
"math/rand" | |
"testing" | |
"time" | |
) | |
/* |
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 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. |
NewerOlder