Skip to content

Instantly share code, notes, and snippets.

View creativemind1's full-sized avatar
🎯
Focusing

Shoeb Mirza creativemind1

🎯
Focusing
View GitHub Profile
@creativemind1
creativemind1 / twoSum.js
Created May 22, 2026 10:15
Two Sum problem
//Hash Method:
function twoSum(nums, target) {
const map = new Map(); // Stores value -> index
for (let i = 0; i < nums.length; i++) {
const complement = target - nums[i];
if (map.has(complement)) {
return [map.get(complement), i]; // Found the two indices
@creativemind1
creativemind1 / countFrequencyOfEachCharacter.js
Created May 22, 2026 10:12
Count Frequency of Each Character in a String
function countLetters(str) {
const smallString = str.toLowerCase();
const obj = {};
for (let i = 0; i < smallString.length; i++) {
if (obj[smallString[i]]) {
obj[smallString[i]] += 1;
} else {
obj[smallString[i]] = 1;
}
}