Skip to content

Instantly share code, notes, and snippets.

View asethia's full-sized avatar

Arun Sethia asethia

  • United States
View GitHub Profile
@asethia
asethia / LinkListRemoveDuplicateUsingHahsMap.scala
Created July 17, 2018 03:00
LinkList remove duplicates using HashMap
package linkedlist
import scala.annotation.tailrec
import scala.collection.immutable.HashMap
/**
* LinkList remove duplicates using HashMap
* Time Complexity O(n)
* Space Complexity O(n) for hashmap if all are duplicates
@asethia
asethia / RotateMatrix.scala
Last active July 15, 2018 19:02
Given an NxN matrix, write a method to rotate the by 90 degrees.
import org.scalatest.{Matchers, FunSpec, WordSpec}
import scala.util.Try
/**
* Given an image represented by an NxN matrix,
* write a method to rotate the by 90 degrees.
* do this in place.
* Time Complexity O(n*n)
* Created by Arun Sethia on 7/8/18.
@asethia
asethia / StringRotation.scala
Last active July 8, 2018 14:20
Assume you have a method isSubstring which checks if one word is a substring of another.
import org.scalatest.{Matchers, WordSpec}
import scala.annotation.tailrec
/**
* Assume you have a method isSubstring which checks if one word is a substring of another.
* Given two strings, 51 and 52, write code to check if 52 is a rotation of 51 using only
* one call to isSubstring (e.g.,"waterbottle"is a rotation of"erbottlewat").
* Time Complexity: O(n)
* Created by Arun Sethia on 7/7/18.
@asethia
asethia / StringCompression.scala
Last active July 12, 2018 03:14
basic string compression using the counts of repeated characters
package arraystring
import org.scalatest.{Matchers, WordSpec}
import scala.annotation.tailrec
import scala.collection.mutable.StringBuilder
/**
* basic string compression using the counts of repeated characters.
* For example, the string aabcccccaaa would become a2b1c5a3.
@asethia
asethia / OneAway.scala
Last active July 18, 2018 15:53
There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character.
import org.scalatest.{Matchers, WordSpec}
import scala.annotation.tailrec
/**
* There are three types of edits that can be performed on strings: insert a character, remove a character,
* or replace a character.
* Given two strings, write a function to check if they are one edit (or zero edits) away.
* pale, pIe -> true
* pales, pale -> true
@asethia
asethia / PalindromePermutation.scala
Last active July 6, 2018 23:59
From given string input can we make Palindrome or not
import scala.annotation.tailrec
/**
* From given string input can we make Palindrome or not
* Input: Tact Coa
* Output: True
* (permutations: "taco cat". "atco cta". etc.)
* Created by Arun Sethia on 7/6/18.
*/
trait PalindromePermutation {
@asethia
asethia / URLify.scala
Last active July 7, 2018 00:00
Write a method to replace all spaces in a string with '%20'
/**
* Write a method to replace all spaces in a string with '%20:
* You may assume that the string has sufficient space at the end to hold the additional characters
* Input: "hello world "
* Output: "hello%20world"
* Created by Arun Sethia on 7/5/18.
*/
trait URLify {
/**
@asethia
asethia / AnagramString.scala
Created July 5, 2018 14:54
Given two strings, write a method to decide if one is a permutation of the other.
import scala.annotation.tailrec
/**
* given two strings, write a method to decide if one is a permutation of the other.
* Created by Arun Sethia on 7/5/18.
*/
trait AnagramString {
final val ASCII_CHAR_LEN: Int = 128
@asethia
asethia / UniqueCharacters.scala
Last active July 25, 2018 19:23
Implement an algorithm to determine if a string has all unique characters.
import scala.annotation.tailrec
/**
* find given string has unique characters
*
* Created by Arun Sethia on 5/21/18.
*/
trait UniqueCharacters {
//ASCII Characters 128
def isUnique(input: String): Boolean = {
@asethia
asethia / KMPAlgorithm.scala
Last active June 15, 2018 16:42
KMP Pattern Matching
package searchpattern
import scala.annotation.tailrec
/**
* KMP Pattern Matching
* inspired from https://www.youtube.com/watch?v=GTJr8OvyEVQ
* Created by Arun Sethia on 6/13/18.
*/
object KMPAlgorithm extends App {