How to Find Number of Digits in an Integer?

To find the number of digits in an integer you can use one of the following methods: (1) Use Iteration (2) Use str()+len() functions (3) Use int(math.log10(x)) +1 (4) Use Recursion Problem Formulation Given: An integer value. Question: Find the number of digits in the integer/number given. Test Cases: Input: num = 123 Output: 3 … Read more

Python Palindromes One-Liner

This one-liner introduces another basic computer science term: palindromes. Similar to anagrams, palindromes are a popular coding interview question. First things first: What is a Palindrome? “A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar or the number 10201.“ [source] … Read more

[Google Interview] The 3 Sum Problem

Company Tags: Google, Adobe, Amazon, Apple, Bloomberg, Facebook, Oracle, Microsoft, Tesla Problem Statement Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Note: that the solution set must not contain duplicate triplets. … Read more

[Google Interview] Detect Capital

Company Tag: Google Problem Formulation We define the usage of capitals in a word to be right when one of the following cases holds: Rule 1: All letters in this word are capitals, like “USA”. Rule 2: All letters in this word are not capitals, like “welcome”. Rule 3: Only the first letter in this … Read more

[Google Interview] Shuffle the Array

Company Tags: Google, Adobe, Apple, Bloomberg, Microsoft Problem Description Given the array nums consisting of 2n elements in the form [x1, x2,…,xn, y1, y2,…, yn]. Return the array in the form [x1, y1, x2, y2,…, xn, yn]. Constraints: 1 <= n <= 500 nums.length == 2n 1 <= nums[i] <= 10^3 Examples Let’s have a … Read more