Posts

Showing posts from September, 2022

DSA GRIND #3

Image
 DSA GRIND #3 By Ashur Baroutta     This week we solved two problems. The first problem reads as follows :  "Given two strings , s and t, return true if "t" is an anagram of "s", and false otherwise". An anagram is a word formed by rearranging the letters of a different word, using the original words letters exactly once (typically).      To solve this I started with setting up an if condition to return false for the edge case in which the length of s did not match the length of t, as if the lengths don't match then the words are obviously not anagrams of each other. I then turned both the strings into character arrays and sorted them. After sorting, I made a for loop and checked each index for a character match, as if one failed to match I knew it was not an anagram. The code submission is shown below. I am pleased with the performance.     The second problem I worked on was a bit more complicated for me though it is built in part on the pre...

DSA GRIND #2

Image
DSA GRIND #2 by Ashur Baroutta      This week I spent most of my free time trying to come up with a solution for a problem called 3Sum. The problem statement reads "Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] equals 0".       A far from easy task for me to accomplish. Given the problem statement pointed out we cant have duplicates return in the trips, the first thing I did was sort the array so it'd be easier to iterate through and account for duplicates. I then initialized a new Linked List data structure in order to store the triplets as an array in each node. At this point I started a for loop and set the exit condition to be the length of the array-2, this is because I'm going to be using the last index as a right hand pointer that we keep sliding over (last index in arrays is always length-1).     After this I set up various conditi...

DSA Grind #1

Image
 DSA GRIND #1 by Ashur Baroutta     The first submission of the new semester will be focusing on the continuation of my data structure and algorithms training. I will be trying to push my limits each week and attacking several more problems to keep different methods/thought processes of problem solving sharp in my mind. Problem #1 : Remove Duplicates From Sorted Array Problem Statement :      "Given an integer array *nums* , sorted in non decreasing order, remove duplicates inplace such that unique elements appear only once, the order of the elements should be kept the same. After this, return k, where k is the number of unique elements remaining in the array. Do not allocate extra space for another array, this must be done by modifying the input array in place with O(1) extra memory (constant space complexity). " Solution :      I start by covering the edge cases with an if statement, if the length of the input array is 1 or 0, simple r...