csweekly.xyz

Weekly coding problems and projects brought to you by the Southern Connecticut State University Computer Science Club

Week #5 DSA

Greatest Common Divisor of Strings

For two strings s and t, we say "t divides s" if and only if s = t + t + t + ... + t + t (i.e., t is concatenated with itself one or more times). Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2. Example 1: Input: str1 = "ABCABC", str2 = "ABC" Output: "ABC" Example 2: Input: str1 = "ABABAB", str2 = "ABAB" Output: "AB" Example 3: Input: str1 = "SC", str2 = "SU" Output: ""

Easy

03-20-2025 05:58 PM

Posted by Mustafa Bolat

Week #4 DSA

Car Fleet

There are n cars traveling to the same destination on a one-lane highway. You are given two arrays of integers position and speed, both of length n. position[i] is the position of the ith car (in miles) speed[i] is the speed of the ith car (in miles per hour) The destination is at position target miles. A car can not pass another car ahead of it. It can only catch up to another car and then drive at the same speed as the car ahead of it. A car fleet is a non-empty set of cars driving at the same position and same speed. A single car is also considered a car fleet. If a car catches up to a car fleet the moment the fleet reaches the destination, then the car is considered to be part of the fleet. Return the number of different car fleets that will arrive at the destination. Example 1: Input: target = 10, position = [1,4], speed = [3,2] Output: 1 Explanation: The cars starting at 1 (speed 3) and 4 (speed 2) become a fleet, meeting each other at 10, the destination. Example 2: Input: target = 10, position = [4,1,0,7], speed = [2,2,1,1] Output: 3 Explanation: The cars starting at 4 and 7 become a fleet at position 10. The cars starting at 1 and 0 never catch up to the car ahead of them. Thus, there are 3 car fleets that will arrive at the destination.

Medium

03-08-2025 08:22 PM

Posted by Mustafa Bolat

Week #1 DSA

Top K Frequent Elements

Given an integer array 'nums' and an integer 'k', return the k most frequent elements within the array. The test cases are generated such that the answer is always unique. You may return the output in any order. Example 1: Input: nums = [1,2,2,3,3,3], k = 2 Output: [2,3] Example 2: Input: nums = [7,7], k = 1 Output: [7]

Medium

02-12-2025 05:02 PM

Posted by Mustafa Bolat