Search Results

50 matches found for 'set'

Javascript Essentials

... s = new StarFox(); var r = new RedFox(); In the class declaration, properties cannot be set in the class scope in that way. The right way to set the properties inside a class is to set them via the constructor.

Unique Permutations

... Lists cannot be hashed because they are mutable data structures. We also don't want to add a set into a set either, since we don't want to store hash tables into hash tables 😦.

Scala Anonymous Functions

Material: A type is basically an alias. It allows for neater code, and simplified readability. Since we can have function types, the code can get really messy when left raw.

Forall and Exists in Scala

... } The above shows Scala code for the forall function, which takes in a predicate function and a set, and checks every value in the set if they satisfy the predicate.

Machine Learning Basics

... levels of the trained model. The model becomes too reliant on the pattern of the training data set, causing test sets to suffer poorly for predictions. Training, Validation, and Test Datasets The best way to view these three datasets: Entire Dataset / \ Training Test / \ Reduced Validation Training Dataset This is the dataset that is used to simply train the model Can be further split into a reduced Training set and a Validation set.

Algorithm Handbook

... run time (ex: nested for loop) \(O(2^n)\) Exponential run time (ex: a power set) Result of \(i\) is result of \(i-1\) multiplied by 2 Example: \(\theta => \theta\) (1) \(a => \theta, a\) (1) \(a, b => \theta, a, b, ab\) (4) \(a, b, c => \theta, a, b, ab, c, ac, bc, abc\) (8) \(O(n!)\) Factorial run time (ex: string permutations) Example: \(a => a\) (1) \(ab => ab, ba\) (2) \(abc => abc, acb, bac, bca, cab, cba\) (6) Bit Operations Sequence of 1's to the right of position \( i \) \( 0000\)\(0000\) => \( 0000\)\(1111\), \(i = 5\) Shift 1 to the left by \(i\) times.

P vs. NP

... game, or figuring out if a number is a prime. P and NP represent complexity classes, which is a set of problems of related resource-based complexity. What is P? P stands for polynomial time.

Longest Substring Without Repeating Characters

... brute force approach is to have double for-loops and convert each sub-array into a set, recording the count of the set each time whenever we find a greater count.

Web Development 101

... spaghetti. Extras: To use React to its greatest potential, Properties (or props), ideally a set of immutable values, are passed to a component's render function. A component should not directly modify any properties passed to it, but should be passed callback functions that instead modifies the store creating a single source of truth.

Python Essentials

... where the function resumes code execution. This is useful when you are iterating through large sets of data (i.e. a list of billions of objects) which takes up more memory than you have available on your machine running the Python code.


... break if is_prime: primes.append(i) return primes By default, we'll set the prime flag to true at the start of each iteration. The modulo operation i % j == 0 tells us that if this evaluation is true, then we have an additional divisor, implying that the number \(i\) is not prime.

Paint adjacent boundaries with distinct colors

... will paint the countries of Africa with distinct colors. For the colors, I was given a domain of set(['red','blue','white','yellow','green']). Additionally, a Python dictionary is given that contains each country and their adjacent countries.

Rotate a 2D Matrix

var jsav = new JSAV("set"); jsav.label("Before rotation").css({"color": "gray"}); var m = jsav.ds.matrix([[0, 1, 2], [3, 4, 5], [6, 7, 8]]); jsav.label("After rotation").

Git the Essentials

Checkouts and Commits Scenario: I want to check out some branch B git checkout <branch B> Scenario: I want to add some files that I updated and commit them git add -i ... (Add your files interactively) git commit Scenario: I created some brand new files and need to commit them.

4 Line Depth-first Search

... a good chunk of performance for nothing. We record the neighbor as a key in the dictionary and set its value to the neighbor's parent, which would be vertex. Because these neighbors are adjacent nodes to vertex, it makes sense that the vertex is the parent, and the neighbors are its children.

Heroku login on a proxy (Windows 7)

... you are in the same boat, you might want to try the following in Command Prompt: C:\...\..> set HTTP_PROXY = <your proxy here> C:\...\..> set HTTPS_PROXY = <your proxy here> Alternatively, go to your environment variables by right-clicking My Computer > Properties > Advanced System Settings (on the left side of control panel) > Environment Variables.

B-Trees vs. LSM Trees

... hash table (or hash index) that keeps track of keys and values. The values would be a byte offset reference inside an append-only log file (that is on disk, not in-memory), which contains the actual value string.

Reversing sublists of singly linked lists

... Since we are trying to reverse the pointers, instead of A -> B, we want to do B -> A. By setting the next pointer of temp to, we are doing B -> A. Lastly, since we want to continue this reversing process multiple times, prev.

Misconceptions of ASCII and Unicode

... 00 in little-endian. Myth: ANSI is different from ASCII This is true; ANSI is a character set standard that builds on top of ASCII to fill out the characters represented by numbers 128-255, borrowing characters from other character sets (Windows-1252, ISO-8859-1).

Useful Links

This is a personal list of useful resources for improving web stacks, frameworks, development, UX, whatever that I come across! Software Engineering The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) Encryption vs.

Scanning for memory addresses with Cheat Engine and ZSNES

... a certain number, so that whenever I take damage, my HP doesn't go down; it stays at the number I set it to, making me invincible. Getting Started First, you're going to need Cheat Engine and an emulator + game file.

AWS Lambda and other Maven projects

... proxy that allows you to create and manage scalable APIs. When a GET request hits an API that is set up by API Gateway, this could also invoke an AWS Lambda function as a handler to do something when that GET request comes in.

A quick look at Scala and the syntax

The syntax in Scala can look confusing very fast.. def exists(s: Set, p: Int => Boolean): Boolean = !forall(s, (x: Int) => !p(x)) p here is a function parameter; okay, I get that.

Misconceptions of Software Engineer interviews at FAANG

... There are lots of services on the web you can use to do mock interviews. Practice learning how to set up problems, talking, explaining, drawing, and illustrating ideas. This will serve as a fundamental backbone, regardless of how good your algorithm game is.

Replace all occurrences of a space inside an array

... where the last character will be in the final array, after the replacements are inserted. We can set this index pointer to \(p_{final}\). Then, find the last non-null character in A, which is the original size of the string in A (we do not want to include the empty null characters in A).

Web Backend Security Headers - 1. CSP Headers

... CSP contents somehow depend on the web application's state. In normal circumstances, CSP would be set in the response header from a load balancer or web application server. Setting this header on a load balancer is relatively straightforward, while for web application servers, it depends on the web framework.

Java Essentials

... this map will be read-only. ImmutableMap.of("key1", "value1", "key2", "value2"); Empty set HashSet<T> s = new HashSet<>(); Set with values HashSet<Integer> s = new HashSet<>(Arrays.

Bloom Filter

A set data structure uses a hashing function to store values and to verify if a value exists. Bloom filters are similar in that it uses multiple hashing functions to store values and to verify if a value exists.

Data Sharding: Twitter Posts

... database server will not be sufficient at this scale, so we need to incorporate a multi-master setup. This means writes will have to be distributed to multiple database servers and we will have to shard the data and try to achieve equal distribution among all the servers.

Big Data Processing: Batching vs. Streaming

... you to switch from one engine to another with ease. However, using Spark natively has its own set of benefits, such as higher performance (when properly tweaked).

Apache Kafka and Event Streaming

... Or maybe you might want to email users instead. Chat Service If you create your topics and set the partition sizes to 1, you can have messages appear in the correct chronological order.

Build a Trie in Python

... or prefix tree, is a kind of search tree—an ordered tree data structure used to store a dynamic set or associative array where the keys are usually strings. Build a trie. Input A class Trie, with an empty constructor and three empty methods insert(word) search(word) startsWith(prefix): Assume that all word inputs are lowercase alphabets Approach The key to building a trie is to define a class that has a container which can house up to 26 keys (1 for each lowercase alphabet).

Local Secondary Index vs. Global Secondary Index

... Secondary Index (LSI) A local secondary index takes the idea above in a distributed database setting where we may have 1 or more partitions that are sharded. In this case, a secondary index is partitioned by some document ID.

Buy and Sell Two Stocks

... \({55, 55, 55, 45, 35, 35, 0}\)* *In the backwards iteration, we start at the last element, set it as the max_so_far and iterate the array to the left. For each element (to the left) that is smaller than the current max_so_far, we calculate the profit and add it to the list -- more precisely at the index of the element we just looked at.

String Manipulation in Python 3+

... .splitlines with no argument provided. If you do want to keep the line breaks in the list result, set the flag keepends=True. str.strip([chars]) "A B C D E F G".strip() => "ABCDEFG" Another quick and easy way to cut out all the spaces just by calling .

Javascript Concepts

Objects new Object() and {} is semantically the same, but the {} is called object literal syntax. To do a deep-copy of an object, use Object.assign(target, src) or in ES6, use the spread syntax. Variables let is a block-level declaration var is a global-level declaration Functions Javascript functions are first-class objects because they can have properties and methods just like any other object.

Cyclic Permutation

... points to 'a', is in the correct position, but we are swapping this value again, effectively setting A[1] to some other value. A is now ['b', 'd', 'c', 'a'], which doesn't look accurate at all with the exception of the placement of 'c', only because c was always in the correct position 2 and was never touched.

Compute the max. water trapped by a pair of vertical lines

Problem An array of integers naturally defines a set of lines parallel to the Y-axis, starting from x = 0 as illustrated in the figure above. The goal of this problem is to find the pair of lines that together with the X-axis "trap" the most water.

Working with Production at Amazon Retail Website

... software stack, meaning that it has its own data stores, server configurations, deployment settings, application runtimes, and so on. If say you have a Pre-Production stack, then this would be a separate stack from the Production stack.

Asynchrony vs. Multithreading

... management: need to handle deadlocks, mutexes Difficult to debug Each thread has a separate set of registers, stack, etc. that it maintains Keep in mind that asynchronous programming and multithreading aren't exactly mutually exclusive depending on the platform; for example with Java 8's CompleteableFuture, asynchronous programming is actually achieved using multithreading.

Forward Proxy and Reverse Proxy

... I go over two variations of proxies. Forward Proxy One day, in a school classroom setting, a teacher wants an anonymous survey filled out by all of the students in the classroom.

Topological Sorting

... perform a topological sort via DFS, you will need the following: Adjacency Lists A "visited" set Recursion Recall that DFS itself will not give you nodes in topological ordering.

Validate a BST

... tree and the direction is changed (i.e. from right to left, or left to right), a new boundary is set for all child nodes. For example, in the binary tree below, 45 is the leaf. 45 is indeed greater than its parent 15, and the subtree only consisting of 15 and 45 is considered a BST, but in the diagram, 45 is greater than 10, while 10 is less than 30.


... not a silver bullet. React and Angular frameworks can build some amazing web apps, but large assets size is often a consequence of that. There is also a greater negative UX when the assets are too big.

Tenets of Leetcode

... Hard problems Hard problems are challenging and rewarding but its not realistic in an interview setting because majority of them are very time consuming. Some problems aren't exactly "Hard" in the algorithm itself, but more so just "Hard" in the coding/structuring phase.

HTML and CSS Concepts

... pairs that are more formally known as property/value pairs. Above, the property being set is background-color and the value is red. Box Model Each HTML element can be seen as a box.

Scaling Instragram Infrastructure

... magnitude. Problem #3: Still high load on DB though Solution #3: Use memcached lease-get, least-set. Good tradeoff for UX like 1 million likes vs. 1 million and 10 likes (some staleness is okay).

Software Methodologies

Agile Agile in a nutshell is basically a set of principles laid out to promote fast and efficient development cycles. Scrum Scrum is an Agile methodology, so it attempts to cover the Agile principles by bringing in processes and rules to help facilitate them.

Data stores in Software Architectures

... SQL writer is not sufficient at the Amazon scale for this, meaning we would need a multi-master setup to horizontally scale the SQL database with sharding and consistent hashing. Solutions: Document Databases / Columnar Databases (ex: MongoDB, DynamoDB, Cassandra) + Distributed Cache Runner-ups: - Relational Databases (ex: SQL) + Distributed Cache Crypto trends within the last year In this problem, we want to figure out the statistical data of cryptocurrency within the last year, down to a minute's granularity.

React HOC vs. Hooks

... hierarchy Split one component into smaller functions based on what pieces are related (such as setting up a subscription or fetching data) Pave the way for optimized code compilation Is one better than the other? The answer is simply put, no.