Skip to content

Instantly share code, notes, and snippets.

@HarshitJoshi9152
Created April 3, 2024 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HarshitJoshi9152/55f89fbe2cb6b1151d1bbd50348bf80d to your computer and use it in GitHub Desktop.
Save HarshitJoshi9152/55f89fbe2cb6b1151d1bbd50348bf80d to your computer and use it in GitHub Desktop.
module Main where
import Data.List (find, groupBy, intercalate, nub, sort, sortBy)
import Data.Ord
import Debug.Trace
-- Solution to
-- https://leetcode.com/problems/largest-number/description/
largest :: [Int] -> String
largest =
intercalate ""
. concatMap (sortBy (comparing length))
. groupBy (\a b -> head a == head b)
. sortBy (comparing Down)
. map show
-- Solution to
-- https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/description/
windows :: (Show a) => Int -> [a] -> [[a]]
windows _ [] = []
windows n a
| n > length a = []
| otherwise = trace "Hello" stx : windows n (tail a)
where
stx = take n a
countGoodSubstrings :: String -> Int
countGoodSubstrings = length . filter (\x -> length x == (length . nub) x) . windows 3
main :: IO ()
main = do
putStrLn $ largest [10, 2]
@HarshitJoshi9152
Copy link
Author

Ooops I forgot to remove unnecessary stuff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment