Given an array of strings, group anagrams together.
Input: ["eat", "tea", "tan", "ate", "nat", "bat"],
All inputs will be in lowercase.
The order of your output does not matter
This is another problem with anagrams that I came across in leetcode. The problem is asking to group all the words that are anagrams of each other in an array inside yet another array. In the above example ate, eat, and tea are all anagrams of each other so they are all grouped in an array inside of a larger array.
Write an algorithm to determine if a number is “happy”.
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.
1^2 + 9^2 = 82
8^2 + 2^2 = 68
6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1…
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
nums1 = [1,2,3,0,0,0], m = 3
nums2 = [2,5,6], n = 3Output: [1,2,2,3,5,6]
My first thought with this problem was to first sort nums1 so all the 0’s would be at the beginning of the array. As long as m was the…
I was building out an admin side for an old project I had. An admin interface is something I don’t think I really came across before, but after some googling and watching youtube videos, I came across something called react admin. React Admin is a framework that allows the user to easily build an admin interface using data from an API. This is exactly what I had been looking for! I read through their tutorial and it seemed simple enough. Install react admin… I used npm so my install looked like this:
npm install react-admin ra-data-json-server
This installed react admin…
I recently did a code challenge that had to do with anagrams. An anagram is two sets of letters that can be unscrambled to match each other like “apple” and “plape”. I’ve come across a simple anagram problem that just checks to see if two sets of letters are anagrams of each other. This problem was a little more complicated: Given an array of strings, remove each string that is an anagram of an earlier string, then return the remaining array in sorted order.
str = [‘code’, ‘doce’, ‘ecod’, ‘framer’, ‘frame’]
The function we create should return the following…
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.
Input: nums = [1,2,3,1], k = 3
Input: nums = [1,0,1,1], k = 1
Input: nums = [1,2,3,1,2,3], k = 2
Maps can be instantiated by the new keyword:
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.
Explanation: Rob house 1 (money = 1) and then rob house…
Given an integer
product, find the smallest positive integer the product of whose digits is equal to product. If there is no such integer, return -1 instead.
product = 1, the output should be
1 x 1 = 1 (1 is not a valid result, because it has only 1 digit)
product = 12, the output should be
2 x 6 = 12
product = 19, the output should be
No valid result found.
product = 450, the output should be
2 x 5 x 5 x 9 = 450
I was working on some algorithm problems when I came across a term I haven’t really come across in my short time as a developer. That term was “set”. A set like an array is a collection of values. The most valuable part of a set is that a value in a set may only occur once. This comes in handy for many algorithm problems I have already encountered.
let arrayOne = [1,2,1,2]let setOne = [...new Set(nums1)]
console.log(setOne)// [ 1, 2 ]
In the above example you can see that you can create a set using the new…