What is a Sorting Algorithm? A Sorting Algorithm is used to rearrange a given array or list of elements, usually according to a comparison operator on the elements. The comparison operator is used to decide the new order of elements in the respective data structure.
The efficiency of an algorithm is mainly defined by two factors, space and time. An efficient algorithm is one that takes less time and less space, but this is not possible simultaneously all of the time. There is often a trade-off between time and space. If you want to reduce the time, then space might…
I don’t know about you, but I grew up with some seriously strict parents, so my inclination to be open to restrictions was shattered at about 10 years old. Fortunately, with age comes wisdom (well… hopefully), or at least experience.
When reading about all the forbidden things in strict mode, you may feel like “why would I ever want to use this in my code?!?!?!” but lets suspend our judgements for a minute and look at how it actually benefits you in the long run (kinda like a curfew in high school)!
Write a function that takes in an array of positive integers and returns the maximum sum of non-adjacent elements in the array. If the input array is empty, the function should return 0.
A few things to remember about the problem:
Let’s walk through an example with the array pictured here.
To solve this problem, the best way to do so is with Dynamic Programming. But what is that? …
Welcome to another fun algorithm I ran into on AlgoExpert explained!
If you open up your phone, the keypad looks like this:
Almost every digit is associated with some letters in the alphabet; this allows certain phone numbers to spell out actual words. For example, the phone number 627–974–7328 can be written as marysgreat.
It’s important to note that a phone number doesn’t represent a single sequence of letters, but rather multiple combinations of letters. For instance, 2 can represent three different letters (a, b, or c).
A mnemonic is defined as a pattern of letters, ideas, or associations that…
Check out this cool algorithm I ran into on AlgoExpert. I like the problem’s apparent simplicity, yet the need to really think it through, with all of its edge cases to be able to successfully solve it. In order to solve it optimally, you have to think outside the box.
Here’s the problem:
You’re given an array of integers where each integer represents a jump of its value in an array. For instance, the integer 2 represents a jump of two indices forward in the array; the integer -3 represents a jump of three indices backward in the array.
I recently completed this HackerRank Problem, that I found very clever and wanted to share! I had compartmentalized the use of stacks and queues separately in my mind, so this expanded my thinking to outside the box. Let’s checkout the problem.
A queue is an abstract data type that maintains the order in which elements were added to it, allowing the oldest elements to be removed from the front and new elements to be added to the rear. This is called a First-In-First-Out (FIFO) data structure because the first element added to the queue (i.e., …
It seems like everyone has an opinion these days about TypeScript. When recently interviewing, I expressed the interest in learning TypeScript, and the advice was “DON’T DO IT!” My nature is to take that as a challenge, and I jumped in to a course hours later. I quickly learned of the bane and the value, and that most people feel VERY strongly one way or the other.
According to Wikipedia:
When starting to learn about associations in Active Record and Ruby on Rails, the rule of thumb was when you come across a many-to-many relationships, create a join class in between. This allows you to break the relationship down into two basic has_many/belongs_to relationships and everything is smooth sailing.
And then my whole boat was rocked.
One morning, while attending the Flatiron School, the day began with a discussion question challenging us to think about and model out a User class having a many-to-many relationship with another user, a user following another user, and a user being followed by another…
What is the truth?!?! Truth is hard to come by these days. With “fake news,” conspiracy theories, and rumors on Facebook and Twitter, contradicting yet all claiming to be true, deciphering what is truth is no easy task. The ethical implications of technology on truth on a macro level is controversial at best. Fortunately, if we focus our attention on a micro level, the source of truth is crystal clear. The source of truth is singular and essential. So what is it? What is the “Single Source of Truth (SSOT)?”
When I was first learning about SSOT, the concept was…