Created
April 3, 2024 15:14
-
-
Save 0xkarambit/55f89fbe2cb6b1151d1bbd50348bf80d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ooops I forgot to remove unnecessary stuff