Search Results


28 matches found for 'strings'

Phone Number Mnemonics in Python

Recursion is a great way to come up with permutations of strings or elements. Not necessarily because of the performance (iterative styles are usually faster) but because of simplicity and organization - like many algorithms with functional programming languages like Scala, recursive functions in general look neater, nicer, and easier to categorize.


String Manipulation in Python 3+

... gives you the index of the first match. While the index might be nice to have, do remember that strings are immutable. str.replace(old, new[, count]) "ahoy m8y".replace("m8y", "matey") => "ahoy matey" This allows you to replace any matching substring old to new.


Python String Tricks - Performance considerations

... make it seem like entries are being deleted. Do note that you cannot do index assignments with strings in Python. This is because strings are immutable. Consider the consequences of += and = operators This is naturally ~\(O(n)\) in time complexity because you are allocating a new string and copying over \n\ elements, where \n\ represents the amount of characters in the new string.


Misconceptions of ASCII and Unicode

... this can result in a large overhead in terms of memory space usage. For this reason, if most strings use ASCII characters, it will be much more space-efficient to use UTF-8. On the flip side, many higher-order characters can take a whopping 3 bytes in UTF-8, while they fit in just 2 bytes in UTF-16.


Escape from the Strings

What is escaping? Escaping is used for characters that are not intended to be shown. Consider the following text: <strong>Hi there</strong> This text is saved onto a HTML file, foo.


Reversing words in a string : the double reverse

Problem Reverse all words (separated by space) in a string Input \(s\) - a string Approach Nice case and point for really examining the examples. First, a few examples of reversing words in a string.


Replace all occurrences of a space inside an array

Problem Given an array of characters, replace all occurrences of a space with another string. Assume that the array has enough space to contain all of the replacements. Input A - An array of characters which may or may not have spaces word - The string to replace spaces with.


Algorithm Handbook

... is not a 0, then the bit at \(i\) is a 1. Strings When constructing strings, use a list in Python and add characters accordingly. The entire string can be returned via "".


A primer on MapReduce

... in some container and transform them. For example, if I want to convert a list of numbers to strings in Javascript: [0, 1, 2, 3].map(number => Integer.parseInt(number)); Reduce Reduce is also known as folding or aggregation.


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

What is PPM? PPM is simply an image format that is very easy to work with, for modifying purposes. We'll create this image format from scratch, using C++. PPM Images can be opened with IfranView. Step 1 - The class for PPM image First, let's define a class for this PPM image.


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.


Longest Substring Without Repeating Characters

Problem Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3.


Data stores in Software Architectures

... the map into \(N\) subdivisions (see image below). The geohash algorithm guarantees that encoded strings with similar prefix are close together. For example, the grid represented by ja83k is guaranteed to be close in proximity to the grid at ja83b.


Decode number of ways

Problem A message containing letters from A-Z can be encoded into numbers using the following mapping: 'A' -> "1" 'B' -> "2" ... 'Z' -> "26" To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways).


B-Trees vs. LSM Trees

B-Trees Modern databases are typically represented as B-Trees or LSM Trees (Log structured merge trees). B-trees are "tried and true" data structures that are popular in database usage, most notably SQL databases.


Java Essentials

JVM Java is a statically typed language that is compiled into bytecode (i.e. with javac) and understood only by the JVM, or Java Virtual Machine. The JVM is an interpreter that reads the Java bytecode and translates them into machine code before execution.


Python Essentials

... pickling is very similar to the json module, which allows you to serialize Python objects into strings and deserialize strings back to Python objects. Few use cases for pickling: You want to convert executable logic in Python into a byte stream and vice-versa.


2023's EOY Tech Buzz Words

Here are some great buzz words to learn so that engineers and colleagues at work will think you're less of an imposter at work ;) Generative AI With the following of ChatGPT, "generative AI" has caught on as a buzz word.


Web Development 101

HTTP vs. HTTPS HTTP stands for Hypertext Transfer Protocol. It typically runs on TCP port 80. It is a protocol for sending data through browsers in the form of webpages and such. One major flaw with HTTP is that it is vulnerable to man in the middle attacks.


Unique Permutations

Problem Given a collection of numbers that might contain duplicates, return all possible unique permutations. Example: Input: [1,1,2] Output: [ [1,1,2], [1,2,1], [2,1,1] ] Input nums - Array of integers Approach The brute force approach is to generate all permutations of \(nums\) and store them into an array.


Useful Links

... Encrypting, Hashing Python Awesome Python CPython Time Complexity PyPy vs CPython strings and bytesarray (Python 3+) Performance Tips Javascript, ES6 ES6 Destructuring Classes suck in Javascript React Hooking up React Redux with Django Backend Import issues with IntelliJ / WebStorm jQuery jQuery Cheat Sheet Chaining vs.


Build a Trie in Python

... 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).


Overlapping linked lists

Given two linked list nodes, one might overlap the other. That is, one linked list might contain a sequence that is already in the other linked list. The two linked lists share a common node. Problem Build a function that takes two singly linked lists and returns a boolean output that signifies whether or not the two linked lists share a common node.


Javascript Essentials

... It just does so much more swiftly than traditional compiled languages.) Lexing is the parsing of strings, splitting them into tokens with semantic meaning (to the compiler/interpreter).


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.


Design Concepts

In this article, I want to go over some fundamental design concepts that are useful for coming up with system design. Requirements Functional Requirements Describes specific behaviors i.e. If a URL is generated, it is composed of a Base64 encoded alias Non-functional Requirements Describes architectural requirements i.


Add SSL certificates to a website

... as passwords, or credit card information, since they will appear as garbled and unintelligible strings in the eyes of snoopers. It offers basic protection against man in the middle attacks.


Scanning for memory addresses with Cheat Engine and ZSNES

... Type to Float/Double. Unfortunately, filtering memory addresses by values such as bytes, floats, strings, etc. can be a bit complicated. At this step, you are practically trying to reverse engineer the game; you are thinking about how and where the data is stored by the game programmer(s).