Leetcode - 670. Maximum Swap
DescriptionYou are given an integer num. You can swap two digits at most once to get the maximum valued number. Return the maximum valued number you can get. 12345Example 1:Input: num = 2736Output: 7236Explanation: Swap the number 2 and the number 7. 12345Example 2:Input: num = 9973Output: 9973Explanation: No swap. 12Constraints:0 <= num <= 108 Approach1234567891011121314151617181920class Solution: def maximumSwap(self, num: int) -> int: result = num num_list = list(...
Machine Learning
Overview of Machine LearningWhat is Machine Learning?Machine Learning (ML) is a subset of artificial intelligence (AI) that enables computers to learn from data and improve their performance over time without being explicitly programmed. ML algorithms build mathematical models based on sample data, known as “training data,” to make predictions or decisions without being explicitly programmed to perform the task. Artificial intelligence is a field of computer science that aims to create machi...
Probability Theory
ProbabilityProbability is a measure of how likely an event is to occur.The probability of an event ( A ) is denoted as: P(A)Probability Calculations Event Formula Complement of A P(A^c) = 1 - P(A) Joint Probability (A and B) P(A \cap B) Union Probability (A or B) P(A \cup B) = P(A) + P(B) - P(A \cap B) Conditional Probability P(A \mid B) = \frac{P(A \cap B)}{P(B)} ExampleA bag contains 10 balls: 6 red and 4 blue. Two balls are drawn randomly without replacement. Let: Event ...
Linear Algebra
Linear AlgebraScalars and Vectors Scalar: A single number representing magnitude only. Vector: An ordered array of scalars representing both magnitude and direction. Row Vector: $\mathbf{x} = [x_1, x_2, \dots, x_n]$ Column Vector: $\mathbf{x} = \begin{bmatrix} x_1 \ x_2 \ \vdots \ x_n \end{bmatrix}$ Vector Operations Transpose: Converts a column vector into a row vector.\mathbf{x}^T = [x_1, x_2, \dots, x_n] Addition: Element-wise addition of two vectors.\mathbf{x} + \mathbf{y} = [x_1+y_1, ...
Derivative
DerivativeThe derivative is a fundamental concept in calculus. The derivative of a function at a specific point represents the rate of change of the function near that point (i.e., the slope of the tangent line to the function’s graph at that point). The essence of a derivative is to provide a local linear approximation of a function using the concept of limits. When the independent variable of function $f(x)$ produces an increment $\Delta x$ at point $x_0$, if the limit of the ratio between...
interview question of Java Backend
Interview QuestionsCore Java (OOPs, Collections, Concurrency Basics)Explain difference between HashMap, HashTable, and ConcurrentHashMap. Feature HashMap Hashtable ConcurrentHashMap Thread Safety Not thread-safe Thread-safe (synchronized methods) Thread-safe (lock segmentation / fine-grained locking) Null Keys/Values Allows one null key and multiple null values Does not allow any null keys/values Does not allow null keys/values Performance Faster (no synchronization overhead) Slowe...
interview question of anthrapic
Question 1: Concurrent Web Crawler ImplementationDesign and implement a multi-threaded web crawler that efficiently crawls a specific domain and counts unique URLs Requirements: Handle circular references and invalid URLs implement rate limiting and exponential back off Process robots.txt compliance Support different URL schemes and redirects Optimize for memory usage with large datasets Overview12345678910111213141516171819[Seed URLs] | [Frontier in-memory queue] <--- [Persistent ov...
terraform
TerraformDocumentationterraform TofuDocumentationtofu
AWS Cloud Fundamentals
AWS Cloud FundamentalsAWS Cli Installationcli AWS Account Creation Root login: When you first create an AWS account, you’ll have a root user login linked to your email address. The root user has full control of the account! Guard this login carefully and use it only for tasks that require it. IAM users: AWS has a system called Identity and Access Management (IAM), which allows you to set up users and roles under your account that have exactly the permissions they need to do certain work. We’l...
01- How to define performance tuning standards
Why Perform Performance Tuning? An online product without performance testing is like a ticking time bomb. You don’t know when it will break down, or what its limits are. Some performance problems accumulate slowly over time and eventually explode. Many more are caused by fluctuations in traffic. Performance tuning is a continuous process that helps you identify and address performance issues before they become critical, ensuring a smooth user experience and optimal resource utilization. Perf...









