Posts

Sunset Views Coding Challenge

Image
    For this weeks challenge I did a problem called sunset views. The challenge is that you are given a list of integers and also a string that is either west or east. The integers in the array represent the height of buildings. Your challenge is to return to the user a new list of indexes that represent the buildings in the list that were given that can see the sunset. I also included a video of me explaining my solution since this problem is easier to understand if I can show you visually my solution. In this portion I will explain how my actual code works.      To start I initialize a couple variables. First is tallest that represents the tallest building in our list, the tallest index, a new building list which will hold the indexes that can see the the sunset and the second tallest that will be initialized to zero. We will have a first loop that will be used to first find the tallest building in ou...

Week 9 Coding Challenges

Image
      For this weeks challenge I did a coding challenge called generate document. The way this works is you are given a function that takes in 2 strings. The first string is called characters and the second is document. Your goal is to see if you can generate a document with the given characters in your string. The only way you can generate a document is if you have the same amount of characters in your character string that will enable you to generate the document. For example if characters = "abcabc" and document = "aabbccc" you can't make the document because you are missing one 'c' in the characters string. If you are able to make the document you will return True to the user else False. This program will also account for spaces to be able to generate the document.      The first thing I thought up when I saw this challenge was to automatically use a for loop. Once I did though I realized I needed a way to ke...

Smallest Difference Coding Challenge

Image
    For this weeks challenge I decided to do another more difficult problem called the smallest difference. The way this challenge works is you are given 2 lists each containing integers. Your job is to return the pair of integers one from each list that produces the absolute difference that is closest to 0. The items you will return will be in a new list containing the pair for example [3,2]. I found a way to create 2 different solutions for this problem and after researching online I am starting to learn optimal solutions for different problems. I have not gotten to the course in my degree that we learn optimal space and time complexity using big 0 notation so I do not know the exact verbiage yet however it is obvious that if you have a solution that requires to for loops instead of just one while loop the 2 for loops will take longer time than the while loop since you have to traverse your lists 2 times.      The first solution...

Three Number Sum Coding Challenge

Image
  This weeks coding problem is called three number sum. The concept of this challenge is you are given an array, and a targetSum value. The array contains integers that are not sorted and a target sum is the target give to see if any 3 values in our array add up to the value of our target sum. If they do add up then we must return a nested list of integers with each list in our list containing 3 values that were in our array that equal our target. This problem is similar to a two target sum problem I have done before but since its 3 number sum this makes it a lot more difficult.     In a 2 target sum coding challenge all you would have to do is use 2 for loops. The first for loop you keep track of the first_index and in your second for loop you loop through the list again but starting at first_index + 1. Then you simply keep track of how many times the sum of those 2 values add the target sum and append those values to your list. However this is a 3 target sum. We co...

Tandem Bicycle Coding Problem

Image
      For this weeks assignment I decided to do one of the longer coding challenges. This one is called tandem bicycle. A tandem bike is a bike that has 2 or more seats on it with every rider pedaling. If there are 2 people riding one bike than the speed of the bike will be determined by the faster peddler and the slower peddler will be ignored. The way this challenge works is you are given an 2 arrays with integer values that represent 2 different groups of riders. One of the groups are red riders and the other group is blue riders. Every index inside of the arrays represent one rider and the value inside of that index determines the speed of the rider. The higher the speed the faster the rider can peddle. You are also given another variable called target which is a boolean and will either be False or True. If the target is True then we are trying to find a way to pair every blue rider with every red rider to find the fastest ...

Binary Tree Challenges

Image
             For this week I decided to step into more complicated challenges that take use of a binary tree. A binary tree is one of the most common algorithms that is used in coding interviews so its important to understand the ins and outs of it. The first image above is a visual image of what the algorithm actually looks like. Think of every circle as a node or an object that is attached to our algorithm. The very first node on the top is called the root node. Every node after that are children nodes and children nodes can also have children nodes as well. When a node is not pointing to anything like the 4, 7, 13 they are called lead nodes. In this case we can take a guess that the values that were put in were in order [8,3,10,14,13,1,6,4,7]. This might be incorrect but its just a guess to explain what is happening in this image. The first value added would be the 8 and it becomes the root node because its the very first node in our tree. Then we a...

Coding Challenges Week 2

Image
    For this week I decided to write solve two different coding problems. As the semester goes on and I get better using Python tools I will attempt to do more every week. The first problem is called minimum waiting time. You are given a list of integers that represent the amount of time in seconds it will take for queries to run. What we are trying to do is give the minimum amount of time it will take to run all those queries. The amount of time a query takes to run is adding all the values before it. If the query is running for the first time its time will be 0 seconds since there are no queries before it. If we are given a list of     [3,2,1,2,6] the minimum waiting time in seconds would be 17 seconds. That is because the time would be calculated as (0) + (1) + (1+2) + (1+2+2) + (1+2+2+3) = 17.     The first steps in solving this problem is to create a variable to hold the total seconds and sort the array from minimum to maximum order. We sort ...