Search Results


18 matches found for 'binary'

Algorithm Interview Problems

Welcome This page contains solutions to common interview problems that may be encountered. Arrays Longest Substring Without Repeating Characters Rotate a 2D Matrix Buy/Sell Two Stocks Merge Intervals Next Permutation Random Permutation Replace all occurrences of a space with a string Linked Lists Reversing sublists of singly linked lists Cycles in singly linked lists Overlapping singly linked lists Merging two sorted singly linked lists Merge k sorted lists Recursion Counting the path of sums Money Denominations Phone Number Mnemonics Unique Permutation Dynamic Programming Perfect Squares Find the Maximum Min Path Binary Trees Tree Symmetry Iterative In-Order Traversal of a Binary Tree Construct a Binary Tree from Pre-Order Traversal and In-Order Traversal BST Validate a BST Binary Heaps Merge k sorted lists Graphs Find a path in a maze from start to finish Flip colors in a matrix Search Search in a rotated sorted array Find the Duplicate Number Greedy Algorithms Queue Reconstruction By Height Trie Build a Trie in Python Invariant Compute the max.


Build a Binary Tree with Pre-order and In-order traversal data

... a pre-order traversal array of integers and an in-order traversal array of integers, construct a binary tree. Input preorder - array of integers inorder - array of integers # Definition for a binary tree node.


Recursive multiply function in Python using + and binary shifts

Here is one way to do an arithmetic multiply on two positive integers only using <<, >>, and +, without using the * or / operators. The idea is to keep shifting n1 to the left by 1, as n2 is shifted to the right by 1.


2's complement on long hexadecimals

2's complement is originally done on binary numbers, but sometimes you might need a binary 2's complement representation of hexadecimal digits. If a hexadecimal value is short enough (say 4 characters), there are a number of methods you can use to get the 2's complement.


Validate a BST

Problem With a binary tree as input, determine if the tree is a BST or not Input node: Has 3 properties .val: Integer value of the node .left: A pointer to another node object, or None if null .


Merge k sorted linked lists

... effectively keep track of the smallest values. Since there are \(k\) linked lists, we can use a binary heap to keep track of \(k\) nodes, since we only need to keep track of at most \(k\) nodes with distinct indices.


Symmetry in a Tree

var jsav = new JSAV("av-sym"); jsav.label("Symmetric tree"); var bt = jsav.ds.binarytree(); bt.root("5"); // set the value of the root bt.root().left("3"); // set left child bt.


Search in a rotated sorted array

... the array is partially sorted, it turns out that this array is still a good candidate for binary search. The key to solving this is to understand your boundaries thoroughly. The traditional binary search algorithm gives you access to the lowest index, the highest index, and using the two indices you can determine the middle index.


Iterative In-Order Traversal

Problem Return the values of a binary tree using in-order traversal, iteratively. Input node: Has 3 properties .val: Integer value of the node .left: A pointer to another node object, or None if null .


Algorithm Handbook

... Trees If an in-order traversal data and pre-order traversal data are both provided, a unique binary tree can be composed. If only one or the other is provided, many binary trees can be composed BST Validate a BST In-order traversal (LNR) provides a sorted traversal in ascending order Reverse in-order traversal (RNL) provides a sorted traversal in descending order Hash Tables There are multiple implementations that use a hash table, and they can be quite different.


How to convert a PPM image to grayscale in C++

... value char *threeChan; // A series of rows and columns (raster) that stores important binary image data }; string magicNumber - For simplicity of this guide, we'll let this be "P6".


Comparison Charts of File Storage Formats

... numbers with precision (i.e. larger than 2^52)Can be quite bloaty in sizeCannot insert raw binary strings; a hacky workaround is to encode them with Base64 Simple, widely used with REST/GraphQL Binary JSON (e.


RDBMS Indexing

... the index created, instead of going through each row until we find id = 99999, we can now do a binary search on the index ids, and find the row we are looking for in \(O(log n)\) time.


Machine Learning Basics

... varying applications. With One Hot Encoding, you basically turn your categorical data into binary data that is classified by state (1 for yes, 0 for no). Note that you will have more columns - one for each classification of the data.


Counting the path of sums

Description Given a binary tree with nodes containing integer values (positive or negative), how can you count up all the paths that equal to some target sum? Note, that the paths do not have to start from the root; it may start from any sub-tree and end at another sub-tree, as long as the path goes down the tree.


OpenVPN / DNS / resolv.conf

... on your distribution. You can try which resolvconf to find the direct PATH to your resolvconf binary file. 4. Configure your OpenVPN Client Lastly, in your OpenVPN client config file, add the following lines: script-security 2 up /etc/openvpn/update-resolv-conf down /etc/openvpn/update-resolv-conf script-security 2 means that OpenVPN is allowed to call built-in executables and user-defined scripts.


Coin Change Denominations

... left side, can we predict the outcome? Each iteration of this function behaves like traversing a binary tree. In one iteration, you either subtract the money from the coins.head, or you chop the head off the coins list.


Data stores in Software Architectures

... or a media streaming service (i.e. Youtube, Netflix, Spotify), we want to think about BLOBs (binary large objects). For that, an object store is the best choice for this, such as Amazon S3.