Q1. Generate Tag for Video Caption
Mode :Easy
Example 1:
Mode :Easy
Example 1:
Input: caption = "Leetcode daily streak achieved"
Output: "#leetcodeDailyStreakAchieved"
Explanation:
The first letter for all words except "leetcode" should be capitalized
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
Q1. Generate Tag for Video Caption Mode :Easy Example 1: Input: caption = "Leetcode daily streak achieved" Output: "#leetcodeDailyStreakAchieved" Explanation: The first letter for all words except "leetcode" should be capitalized
Status: Done ✅
Code:Kotlin
IDLE : Intellij
Code :
@leetcode7
#leetcodecontest #leetcode #contest
Code:Kotlin
IDLE : Intellij
Code :
class Solution {
fun generateTag(caption: String): String {
val words = caption
.split("\\s+".toRegex())
.map { it.filter(Char::isLetter) }
.filter(String::isNotEmpty)
val camel = words
.mapIndexed { idx, w ->
w.lowercase().let { low ->
if (idx == 0) low
else low.replaceFirstChar { it.uppercaseChar() }
}
}
.joinToString("")
return ("#$camel").take(100)
}
}@leetcode7
#leetcodecontest #leetcode #contest
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
Q2. Count Special Triplets Status: Medium #leetcodecontest #leetcode #contest
🔌 Problem Explanation:
We have an integer array nums of length n. A special triplet is a triple of indices (i, j, k) such that:
We want to count how many such triplets there are, and return the result modulo 10**9+7 (to avoid overflow).
#leetcodecontest #leetcode #contest
We have an integer array nums of length n. A special triplet is a triple of indices (i, j, k) such that:
0 <= i < j < k < n
nums[i] == 2 * nums[j]
nums[k] == 2 * nums[j]
We want to count how many such triplets there are, and return the result modulo 10**9+7 (to avoid overflow).
#leetcodecontest #leetcode #contest
Easy 🗿
Q2 Solved🗿
Code 🧑💻: Kotlin
IDLE: Intellij
@leetcode7 #leetcodecontest #leetcode #contest
Q2 Solved
Code 🧑💻: Kotlin
IDLE: Intellij
class Solution {
fun specialTriplets(nums: IntArray): Int {
val MOD = 1_000_000_007L
val n = nums.size
val maxVal = nums.maxOrNull() ?: 0
val limit = maxVal * 2
val rightCount = LongArray(limit + 1)
val leftCount = LongArray(limit + 1)
for (v in nums) rightCount[v]++
var result = 0L
for (j in nums.indices) {
val mid = nums[j]
rightCount[mid]--
val t = mid * 2
if (t <= limit) {
result = (result + leftCount[t] * rightCount[t]) % MOD
}
leftCount[mid]++
}
return result.toInt()
}
}@leetcode7 #leetcodecontest #leetcode #contest
Please open Telegram to view this post
VIEW IN TELEGRAM
Let's get to 250 subscribers and I'll share the rest.
@leetcode7 #leetcodecontest #leetcode #contest @azamovme @leetcode #q1 #q2 #q3 #q4
@leetcode7 #leetcodecontest #leetcode #contest @azamovme @leetcode #q1 #q2 #q3 #q4