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
<?php | |
include("Lib.php"); | |
class ImageResizerMultiProcess | |
{ | |
private $sizes = []; | |
public function setSizes($sizes) | |
{ |
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
# Shoot off 300 requests at the server, with a concurrency level of 10, to test the number of requests it can handle per second | |
# -p POST | |
# -H Authentication headers | |
# -T Content-Type | |
# -c Concurrent clients | |
# -n Number of requests to run | |
# -l Accept variable document length | |
# -k Connection keep-alive | |
# -v Verbosity level |
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
import time | |
import uuid | |
class PrintRandom(object): | |
def execute(self) -> None: | |
while True: | |
self.print_number(uuid.uuid1().int) | |
time.sleep(1) |
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
""" | |
Given a node in a binary search tree, find the in-order successor of that node in the BST. If that node has no | |
in-order successor, return null. | |
The successor of a node is the node with the smallest key greater than node.val. | |
You will have direct access to the node but not to the root of the tree. Each node will have a reference to its | |
parent node. Below is the definition for Node: | |
class 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
""" | |
Given an array arr of distinct integers and a nonnegative integer k, write a function findPairsWithGivenDifference that | |
returns an array of all pairs [x,y] in arr, such that x - y = k. If no such pairs exist, return an empty array. | |
Note: the order of the pairs in the output array should maintain the order of the y element in the original array. | |
input: arr = [0, -1, -2, 2, 1], k = 1 | |
output: [[1, 0], [0, -1], [-1, -2], [2, 1]] | |
input: arr = [1, 7, 5, 3, 32, 17, 12], k = 17 | |
output: [] |
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
/** | |
* Implementation of stack using Linked list | |
* Average Time Complexity | |
* Insert/delete Θ(1) | |
* Search Θ(n) | |
* Space complexity: O(n) | |
*/ | |
#include <cstdlib> | |
#include <stdio.h> | |
#include <malloc.h> |
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
""" | |
There is a binary tree with N nodes. You are viewing the tree from its left side and can see only the leftmost nodes | |
at each level. Return the number of visible nodes. | |
Note: You can see only the leftmost nodes, but that doesn't mean they have to be left nodes. The leftmost node at a | |
level could be a right node. | |
Signature | |
int visibleNodes(Node root) { | |
Input |
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
""" | |
Given a list of n integers arr[0..(n-1)], determine the number of different pairs of elements within it which sum to k. | |
If an integer appears in the list multiple times, each copy is considered to be different; that is, two pairs are | |
considered different if one pair includes at least one array index which the other doesn't, even if they include the | |
same values. | |
""" | |
from unittest import TestCase | |
def numberOfWays(arr, k): |
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
""" | |
Given a binary tree, flatten it to a linked list in-place. | |
For example, given the following tree: | |
1 | |
/ \ | |
2 5 | |
/ \ \ | |
3 4 6 |
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
""" | |
Average time complexity: O(nLogk) | |
""" | |
from heapq import heapify, heappop, heappush | |
from unittest import TestCase | |
def sort_nearly_sorted_array(array: list, k: int) -> list: | |
heap = array[:k + 1] | |
heapify(heap) |
NewerOlder