Code
Leetcode - Build Array From Permutation (1920)
· ☕ 1 min read · ✍️ devoalda
Description Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it. A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive). Example 1 2 3 4 5 6 Input: nums = [0,2,1,5,3,4] Output: [0,1,2,4,5,3] Explanation: The array ans is built as follows: ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]] = [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]] = [0,1,2,4,5,3] {: file="Input/Output”}

ARM Assembly - Hello World!
· ☕ 3 min read · ✍️ devoalda
Installation I’m using WSL to build and run the ARM assembly code, these are the installation packages I used: 1 sudo apt install gcc-arm-linux-gnueabi make git-core ncurses-dev qemu qemu-user {:file="Installation on Windows WSL”} Code Simple program to return a number to shell .global _start .section .text _start: mov r7, #0x1 @ System call number for exit (0x1) mov r0, #32 @ Exit code 32 (Returns 32 to the shell) swi 0 @ Software interrupt .

HackerRank - Minimum Height Triangle
· ☕ 2 min read · ✍️ devoalda
Introduction Given integers b and a, find the smallest integer h, such that there exists a triangle of height h, base b, having an area of at least a. Example Input Output 1 2 3 4 # Input: 2 2 # Output: 2 {: file="Input and Output” } Explanation: The task is to find the height of the triangle having base b = 2 and area a = 2.

The Factorial Function
· ☕ 2 min read · ✍️ devoalda
The Factorial Function The factorial function is a mathematical function that takes a non-negative integer n and returns the product of all positive integers less than or equal to n. The factorial function is denoted by n!. This is a reference page for the factorial function, written in C and Python. Background The first 10 factorials are: n n! 0 1 1 1 2 2 3 6 4 24 5 120 6 720 7 5040 8 40320 9 362880 10 3628800 Where $n!

HackerRank - Project Euler #1: Multiples of 3 and 5
· ☕ 2 min read · ✍️ devoalda
Introduction If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. Input and Output Format 1 2 3 4 5 6 7 # Input: 2 10 100 # Output: 23 2318 {: file="Input and Output” }

HackerRank - Handshake
· ☕ 1 min read · ✍️ devoalda
Introduction At the annual meeting of Board of Directors of Acme Inc. If everyone attending shakes hands exactly one time with every other attendee, how many handshakes are there? Input and Output Format 1 2 3 4 5 6 7 # Input: 2 1 2 # Output: 0 1 {: file="Input and Output” } Process This is a math challenge. So using the primitive way of counting, I counted the number of handshakes for each number of attendees, I came up with this:

Leetcode - Two Sums(1)
· ☕ 2 min read · ✍️ devoalda
Introduction Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Input and Output 1 2 3 Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].

HackerRank - Sherlock and Divisors
· ☕ 2 min read · ✍️ devoalda
Introduction Watson gives an integer N to Sherlock and asks him: What is the number of divisors of N that are divisible by 2? Input and Output Format 1 2 3 4 5 6 7 8 # Input: 2 9 8 # Output: 0 3 {: file="Input and Output” } Explanation 9 has three divisors 1, 3 and 9 none of which is divisible by 2. 8 has four divisors 1,2,4 and 8, out of which three are divisible by 2.

HackerRank - Printing Tokens
· ☕ 2 min read · ✍️ devoalda
Introduction Given a sentence, s, print each word of the sentence in a new line. Input and Output Format 1 2 3 4 5 6 7 # Input: This is C # Output: This is C {: file="Input and Output” } Process This was a pretty simple challenge. Completing the code, I’ve added a for loop to print each character at a time, scanning for any blank spaces and “replacing” that with a newline escape character \n.

Leetcode - Concatenation of array(1929)
· ☕ 2 min read · ✍️ devoalda
Introduction Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed). Specifically, ans is the concatenation of two nums arrays. Return the array ans. Example 1 2 3 4 5 Input: nums = [1,2,1] Output: [1,2,1,1,2,1] Explanation: The array ans is formed as follows: - ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]] - ans = [1,2,1,1,2,1] Process This was a pretty simple one other that figuring out how to use malloc again.

Leetcode - Ugly Number(263)
· ☕ 2 min read · ✍️ devoalda
Introduction Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Given an integer n, return true if n is an ugly number. Input and Output Format 1 2 3 Input: n = 6 Output: true Explanation: 6 = 2 × 3 Process This was my thought process while attempting this challenge.

Exercism - Difference of Squares
· ☕ 2 min read · ✍️ devoalda
Introduction Find the difference between the square of the sum and the sum of the squares of the first n natural numbers. The square of the sum of the first ten natural numbers is $(1 + 2 + … + 10)^2 = 55^2 = 3025$. The sum of the squares of the first ten natural numbers is $1^2 + 2^2 + … + 10^2 = 385$. Hence the difference between the square of the sum of the first ten natural numbers and the sum of the squares of the first ten natural numbers is $3025 - 385 = 2640$.