# FCC: Profile Lookup Solution:

So I thought I got the correct solution pretty quickly but it would only pass 2/5 test cases.  Turned out, it was because I was returning “No such contact” inside the outer if statement.. Advertisements

# FCC: Nesting For Loops

Instructions:

Write a function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr.

Solution:

• Iterate through inner subarrays with j.
• Then iterate through the outer array with i.
• Multiply each item with the stored result (product) as you iterate. Test Cases: # Hackerrank Day 0: Weighted Mean Solution in Ruby: I think I could have calculated the numerator with a for loop, but wasn’t sure how to do it.  Need to review other loops  as I usually default to while loop for everything now.

# Hackerrank Day 11: 2D Arrays  My Solution in Ruby: This problem was a lot easier to tackle once I’ve sketched out the formula for calculating each hourglass.  That’s why I bought a notebook to derive future algorithms!

Also downloaded git and cleaned up my github today!  A few commands to remember when adding files and committing changes:

1. Stage the file: git add .filename
• stage a folder with files: git add folder/subfolder/*
2. Commit: git commit -m “enter notes/messages about the changes
3. Push to master branch: git push origin master
• Push to another branch: git push origin BRANCH_NAME

# Hackerrank Day 6: Let’s Review

Task

Given a string, S, of length N that is indexed from 0 to N1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line (see the Sample below for more detail).

Input Format

The first line contains an integer, T (the number of test cases).
Each line ii of the T subsequent lines contain a String, S.

Constraints

• ≤ 10
• ≤ length of 10000

Sample Input

2
Hacker
Rank


Sample Output

Hce akr
Rn ak

Explanation

Test Case 0: S=“Hacker”
S=“H”
S=“a”
S=“c”
S=“k”
S=“e”
S=“r”
The even indices are 0, 2, and 4, and the odd indices are 1, 3, and 5. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S‘s even indices (Hce), and the second string contains the ordered characters from S‘s odd indices (akr).

Test Case 1: S=“Rank”
S=“R”
S=“a”
S=“n”
S=“k”
The even indices are 0 and 2, and the odd indices are 1 and 3. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S‘s even indices (Rn), and the second string contains the ordered characters from S‘s odd indices (ak).

My solution:

So I had a hard time with this challenge because I misunderstood the problem.  I thought the T and S arguments were independent of each other.  However, they are not.  The value of S is dependent on the value of T.  So for each test case (T), there is one substring (S).  Thus, the trick is to use T to prompt the number of user inputs for S, and then store the value of S in an array.

Took me an entire day and 1 Kevin Liu to figure all of this out. Original problem here.

# Hackerrank Day 5: Loops

Task
Given an integer, n , print its first 10 multiples. Each multiple n x i (where 1≤ 10) should be printed on a new line in the form: n x i = result.

Input Format
A single integer, n.

Output Format
Print lines of output; each line i (where 1≤ 10) contains the of in the form:
n x i = result.

Sample Input

2


Sample Output

2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20


My Solution in Ruby: # Chess Board

Write a program that creates a string that represents an 8×8 grid, using newline characters to separate lines. At each position of the grid there is either a space or a “#” character. The characters should form a chess board.

Passing this string to console.log should show something like this:

 # # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #

When you have a program that generates this pattern, define a variable size = 8 and change the program so that it works for any size, outputting a grid of the given width and height.

Solution: To know whether to put a space or a hash sign at a given position (or coordinate), check if the sum of x + y is even or odd.  (all the locations with space are even, and hash are odd).

Example:

location where (x, y) are (1, 1):

1 + 1 = 2 % 2 == 0 => true aka it’s even, you add a space there.

location at (2, 1):

2 + 1 = 3 % 2 == 0 => false aka it’s odd.  So you add a hash.