# Shuffle It Up

Hey guys, I hope your Tuesday was amazing! For today’s algorithm problem, I’m going to write a function that can take in an array of length 2n, and returns a new array with the inputs shuffled. Here’s a bit more insight into what I mean:

`Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].Return the array in the form [x1,y1,x2,y2,...,xn,yn].`

And here’s an example:

`Input: nums = [2,5,1,3,4,7], n = 3Output: [2,3,5,4,1,7] Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7].`

To start off, I created a new array and began…

# One More Change…

Hey everyone, I hope your week was off to a great start! For today’s algorithm problem, I’m going to write a function that can see how many steps have been taken to edit a string, and if only one has been taken, the function would return true. The steps you can perform on a string are either:

• Changing one character
• Deleting one character
• Inserting one character

Here’s an example:

`Input: pale, baleOutput: TrueInput: bake, paleOutput: False`

To start I thought about how I could compare the two strings, and what their lengths would mean. For example, if…

# Palindrome Permutation

Hey everyone, I hope you had an amazing weekend! Did you guys make some time for yourselves or did you do some extra work to help you later in the week?? Let me know! For today’s algorithm problem, I’m going to write a function that can return true or false if an inputted string can be permutated in any way to create a palindrome. Here’s an example:

`Input: Tact CoaOutput: True (permutations: "taco cat", "atco cta", etc.)`

In order to solve this problem, we have to actually think about what a palindrome looks like. Well, for starters it should…

# URLify the String

Hey everyone, I hope your Saturday was amazing and your weekend was off to a great start! For today’s algorithm problem, I’m going to write a function that can turn a string with spaces into a URL. Here’s an example:

`Input: "Mr John Smith"Output: "Mr%20John%20Smith"`

Do you guys remember how often I use JavaScript’s built-in functions? A lot! So why not use them one more time right? For this one, I’m going to use .split() and .join(). The first one will be used to split up each word with a space before or after it, while the second one…

# Unique Characters

Hey guys, I hope your Friday was amazing and you had a productive work week. For today’s algorithm problem I’m going to write a function that` can return true if all characters in a string are unique and false if there are repeating characters. Here’s an example:

`Input:"123456^&*(-=";Output: TrueInput:"1124356789*&^%";Output: False`

So I started out by doing some research and found out that there’s basically only 128 possible unique string characters that you could use. Here’s a quick link to help you review:

Knowing this made me write my first logic statement where if the input’s length was…

# Consecutive Integers

Hey guys, I hope your Thursday was amazing! For today’s algorithm problem, I’m going to design a function that can tell you how many ones are appearing consecutively in a binary array. Here’s an example:

`Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s.    The maximum number of consecutive 1s is 3.`

I thought this answer was pretty simple, and I started out of course, by declaring a max variable and a count variable. I then iterated through the array and if there are consecutive ones, the count gets incremented each time…

# What’s Smaller

Hey guys, I hope your Wednesday was great! For today’s algorithm problem, I’m going to design a function that takes in an array of integers and returns a separate array which tells you how many numbers are lower than each entry of the original array. Here’s an example:

`Input: nums = [8,1,2,2,3]Output: [4,0,1,1,3]Explanation: For nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3). For nums[1]=1 does not exist any smaller number than it.For nums[2]=2 there exist one smaller number than it (1). For nums[3]=2 there exist one smaller number than it (1). …`

# Finding a Common Character

Hey guys, I hope your Tuesday was amazing! For today’s algorithm problem, I’m going to create a function that can detect what the common characters are in an array of strings. Here’s an example:

`Input: ["bella","label","roller"]Output: ["e","l","l"]Input: ["cool","lock","cook"]Output: ["c","o"]`

I started off by iterating through the array and making a copy of the original array’s first element. The consequent iterations would compare each entry to the other entries by using a .filter() built-in method. I filter the new array and return the array once it goes past a certain length, the length of the original array. …

# Removing an Element

Hey guys, I hope you all had a great day and our week was off to a great start! For today’s algorithm problem, I’m going to write a function that takes in an array and a value and returns the same array with the value taken out of the array. Here are a couple of examples:

`Input: nums = [3,2,2,3], val = 3Output: [2,2]Input: nums = [0,1,2,2,3,0,4,2], val = 2Output: [0,1,3,0,4]`

So when I started out solving this problem, I thought of having two pointers run through the array and having a counter incremented each time an…

# Is There a Copycat?

Another Sunday, and another week has gone by! I hope all of you guys were productive this weekend and got stuff done. For today’s algorithm problem, I’m going to write a function which basically takes in an array and returns true if there are any duplicates, and false if there aren’t any. here’s an example:

`Input: [1,2,3,1]Output: trueInput: [1,2,3,4]Output: falseInput: [1,1,1,3,3,4,3,2,4,2]Output: true`

So when I started solving this problem, I sorted the input array and just decided that if a number showed up more than once, the function would return true once I start iterating…

## Setu Potnis

A university student wanting to learn more as well as share my journey about learning software

Get the Medium app