Posts

Stock Market Max Profit

Image
      For this week I did a problem called maxProfit. I found that this problem was actually a bit more practical for real life. The problem is that you are given a list containing integers that represent the price of a stock at a certain day. For example a list of [4,3,2,6,8,1,18,3,5,7]. For example at index 0 the stock was at 4 dollars and index 1 the price was 3 dollars. We would want to buy the stock at the lowest price possible and sell the stock at the highest price possible. For example in this case we would want to buy at price 1 and sell at price 18. We take the difference of that and our profit would be 17.      At first I thought right away of going to a double for loop and taking the difference at every step and seeing if that was the max profit. I however have been reading about big o(N) notation and that would not be optimal. That would be O(N^2). I thought about a faster solution where would would just go through the list once and have ...

Coding Challenges

Image
      For this week I did 2 more coding problems. The first one I did was more challenging and its called isIsomorphic. Lets say we have 2 strings and a holds the value of the first string and b holds the value of the second string. Two strings are isomorphic only if you can replace all the characters in a with all the characters in b. That means that all the occurrences of a character in a string a must map directly back to another character in the string b. They must back and forth together in order for it to be isomorphic. For example the string abb is isomorphic with the string cdd. That is because for every a character you can replace it with the character c. Also every b character you can replace it with the letter d. In our problem we can also assume that both strings that are given will always be of equal length.      When I first started the problem right away I thought to create a dictionary. We could loop through the strings a...

Pointers in C

Image
      For this weeks assignment I will demonstrate a technique I actually just learned this semester in one of my csc classes. It is the idea of pointers. I am currently learning about C. The interesting part about C is the concept of pointers that I did not realize we were already using in java. A pointer is a a variable that holds the memory of an address location in your memory. Instead of actually holding a value it holds a location that you can use and pass as a parameter to a function if you want to edit that variable in another function. If you were just to pass a value as a parameter the function would only get a copy of the value and if you try to edit it in the function the function that it got called from wouldnt update. I will explain what is going on in my code for an example.     The program I wrote is dice rolling game. I only posted my main and my player turn function to show how pointers work. In C the first thing y...

Ping Pong in Python

Image
      For this weeks assignment I decided to learn how to make a game using Python. I have been looking up online how to get better at coding and other than doing coding challenges its useful to create real world projects to put everything together. I learned so much just from doing this project that I didn't know from just doing coding challenges. Now this is 147 lines of code so I wont explain every single detail but I did leave comments on all of my code so you can go through it and understand what each block of codes adds to the game.I will also upload a video at the end of this page so you can see the game working in real time.     The first thing I had to do is import a built in library in Python called Turtle. It allows you to draw different objects and animations on to your screen. Once I installed Turtle I created a variable holding the Turtle.Screen function that allows me to create a screen that pops up. Once I did t...

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 ...

First Non Repeating Character Coding Challenge

Image
      For this semester I will be solving different coding problems that are commonly asked in developer interviews. I have applied for several developer internships this last month and need to get prepared on solving these problems along with being able to explain my solutions. The first problem I did this week is called first non repeating character.     The goal of this problem is to be able to write a function that takes in a string. You want to be able to return the index of the first non repeating character in the string. For example if you are give the string "aabbcddee" the first non repeating character would be the letter c. In this case you would return the index number 4. If you were given the string "aabbccddee" you would return -1. This is because part of the problem is if there is not a non repeating character is a string then we just return -1.     The way I go about these problems is I try to break it down into smaller problem...

Agregate functions in SQL

Image
      Aggregating functions is used to find values out of our data in SQL. Say for example if we have a books database we can group our data by authors then find out how many total books an author has written  by aggregating that query. There are many different aggregating functions in SQL but the ones I am going to focus on today are COUNT, AVG, and MIN.     The COUNT function allows you to count the total number of data in a specific row after we group our data. For example in the screenshot I attached we are using the books table. We are gathering all the first names and last names from the table. Once we do that we group by author first name that way any authors that have the same first name in our table. Once we do that we call the function COUNT(*) to count the number of duplicates in that row. That would give us the total number of books that specific author has written based off our database.     The...

SQL CRUD Commands

Image
      In SQL there is an acronym know as CRUD. This stands for create, read, update, and delete. These 4 terms are the 4 basic actions that are used to manipulate your database. I am going to briefly touch each one because there is so much to write about in each CRUD command. One you understand these 4 commands you have a good basic understand of how to write SQL queries.      We are going to start with create. The create command is when a user inserts new data(row) into a database. This is done using the INSERT INTO key. The way the format goes is you do INSERT INTO <table_name>(column_1, column_2) VALUES ('value_1',value_2').  After table name you designate the name of the columns that you are inserting data into and you must have the same amount of values after the VALUE keyword. In SQL every command also ends with a ; symbol just like in java. Your values must also have the same data type as the columns you are selecting or else this will cau...

INSERTING DATA SQL

Image
      This week in my SQL journey I learned about how to insert data into table in a database. In this case I already have a database I have created called book_shop. I created this database by following along a curriculum that I found on Udemy. I already have MYSQL workbench connected with MYSQL terminal which makes it a lot more user friendly. In order to view the databases you have created in SQL you call the command SHOW DATABASES;  and it shows all the databases that are currently in your DBMS. In the screenshot I attached you will see there is a book_shop and customer_orders which I have created. The other 4 are databases that default in every MYSQL database.     In SQL the command that is used to insert data is INSERT INTO <table_name, table_name> (column_name) VALUES (value, value);.  The words that are capitalized are the actual SQL keywords and the other would just be the names of the table and columns you are using. The first...

SQL

Image
         This week I will be sharing the progress I have made in my android development journey. A big part of developing apps is also being able to store data in an organized way. The most popular way big companies do that is by using a database management system as known as DBMS. I used to always hear about SQL and MYSQL and wondered what is the difference? I took a dive into databases and learned that SQL is the language itself and MYSQL is the database management system that actually holds the data. There are many different types of DBMS suck as MYSQL, Oracle, Microsoft SQL, and others. I chose MYSQL because I looked online to different internship opportunities and it looks like the most popular is MYSQL.      I started with first having to install the correct programs on my computer. This was a bit difficult on its own since databases are a bit complicated. I first installed MYSQL command line client. This is just a black ...

Android Application Buttons

Image
      This week I learned a bit more about the way Android applications are built. I started learning about the button objects in android development. A button is just what it sounds like a button you attach to the screen however the logic of the button is attached by your java file. In this week I decided to have different buttons on the screen and depending on what button the user clicks a toast message would appear. A toast message is just a message that appears that stays on your screen for 3 seconds the goes away. The toast message that I made appear just says "You have just clicked the (color) button". It may seem simple but there are many things going on in the background.          When I placed these button objects on the screen I attached an ID to them to make a connection to them in my java file. Once they are all properly identified I connect them in my java file by calling a built in method. Once I did that I implemented...

Android Application Build

Image
         This week I started to get more familiar with how to build an android application. There is so much material to learn but this week I focused on some specific components. When I took Java I learned about objects and I understood the concept but it was hard to put it together in my mind how this worked in the real world. Once I started messing around with different tools in Android Studio it gave me a better idea of how objects actually work in real life usage.      In android applications you can thing of an object as an item on the screen. Every component on the screen is added by adding coding into your XML file. The EditText component is how we gather user input which is the first three lines on my screenshot. There is also another component called TextView which just shows a text to the user which are the last 3 lines you see on both images. In this example I am asking for user first name, last name and email. Once they submit their i...

My First Android App

Image
         In this weeks assignment I decided to write about something new that I started learning about. So to give you some context I have mentioned before that in school so far I have learned java and currently learning assembly language. I started learning python on the side but recently had a conversation with a friend who has been a developer for 10 years and gave me a suggestion. He said instead of trying to learn multiple languages try to become a master of one. It's like the old saying that says "Fear the man that has practiced one technique 1000 times not the man that knows 1000 techniques". That really sunk in so I decided to look up what can I do with java? I found out that Java is one of the languages that is used to develop android applications. So I decided it was time to take a dive and jump into my first project.      I started watching a tutorial on youtube on how to build an android applicat...