Skip to content

Instantly share code, notes, and snippets.

View shaaslam's full-sized avatar

Shahrukh Aslam shaaslam

View GitHub Profile
@shaaslam
shaaslam / privacy-policy-as.md
Last active February 6, 2025 03:46
Privacy Policy for "Animal Sounds – Learn & Play

Privacy Policy for "Animal Sounds – Learn & Play"

Square Bytes Inc.
Last Updated: 02-05-2025

📌 Introduction

Welcome to Animal Sounds – Learn & Play! 🐾🎵 Your privacy is important to us, and we are committed to protecting your personal data. This Privacy Policy explains how we collect, use, and safeguard your data when using our app.

By downloading and using Animal Sounds – Learn & Play, you agree to this Privacy Policy.


@shaaslam
shaaslam / BinarySearch.java
Created December 24, 2021 14:25
Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.
class BinarySearch {
public int search(int[] nums, int target) {
int mid, left = 0, right = nums.length - 1;
while (left <= right) {
mid = left + (right - left) / 2;
if (nums[mid] == target) return mid;
if (target < nums[mid]) right = mid - 1;
else left = mid + 1;
}
return -1;
@shaaslam
shaaslam / SortedArraySquares.java
Created December 24, 2021 13:51
Given a sorted array, create a new array containing squares of all the numbers of the input array in the sorted order.
class SortedArraySquares {
public static int[] makeSquares(int[] arr) {
int n = arr.length;
int[] squares = new int[n];
int highestSquareIdx = n - 1;
int left = 0, right = arr.length - 1;
while (left <= right) {
int leftSquare = arr[left] * arr[left];
int rightSquare = arr[right] * arr[right];
@shaaslam
shaaslam / PairWithTargetSum.java
Created December 23, 2021 06:02
Pair with Target Sum, Given an array of sorted numbers and a target sum, find a pair in the array whose sum is equal to the given target. Write a function to return the indices of the two numbers (i.e. the pair) such that they add up to the given target.
package io.eductive.twopointers;
public class PairWithTargetSum {
public static int[] search(int[] arr, int targetSum) {
int start = 0;
int end = arr.length - 1;
while (start < end) {
int currentSum = arr[start] + arr[end];
if (currentSum < targetSum) start++;
else if (currentSum > targetSum) end--;
@shaaslam
shaaslam / DecodeString.java
Created March 27, 2018 17:45
Given an encoded string, return its decoded string
package com.shaaslam.strings.classwork;
import java.util.Stack;
/*
* 394
* Given an encoded string, return its decoded string
* You may assume that the input string is always valid;
* No extra white spaces, square brackets are well-formed, etc.
* FUll QUESTION : https://leetcode.com/problems/decode-string/description/
@shaaslam
shaaslam / IsUnique.java
Created March 26, 2018 22:03
Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?
package com.shaaslam.strings;
public class IsUnique {
/*
* works only for a-z i.e. 26 characters
* T = O(n)
* S = O(1)
*/
public static boolean isUnique(String s) {
if(s.length() > 26) return false;
@shaaslam
shaaslam / FindLCP.java
Last active February 22, 2018 19:00
Write a function to find the longest common prefix string amongst an array of strings.
/*
* Longest Common Prefix
*
* Iterating over the trie, starting from the root
* If the current TrieNode is not a word and has only one child
* We will append the key and reassign current with the value (i.e. again instance of TrieNode)
* Once we found the word or more than one child or reach to the end of trie (where current becomes null)
* We will return the final string
*
* Time Complexity : O(n) where n is the longest prefix found
@shaaslam
shaaslam / GroupSum.java
Created February 13, 2018 21:43
Given an array of ints, is it possible to choose a group of some of the ints, such that the group sums to the given target? This is a classic backtracking recursion problem.
package com.shaaslam.recurrsion;
/*
* Given an array of ints, is it possible to choose a group of some of the ints,
* such that the group sums to the given target?
* This is a classic backtracking recursion problem.
* Once you understand the recursive backtracking strategy in this problem,
* you can use the same pattern for many problems to search a space of choices.
* Rather than looking at the whole array, our convention is to consider the part of the array
* starting at index start and continuing to the end of the array.
@shaaslam
shaaslam / PermuteArray.java
Created February 12, 2018 22:12
Write a function permute that accepts an array of strings as a parameter and outputs all possible rearrangements of the strings in the array. The arrangements may be output in any order.
package com.shaaslam.recurrsion;
import java.util.ArrayList;
import java.util.Arrays;
/*
* Write a function permute that accepts an array of strings as a parameter and outputs
* all possible rearrangements of the strings in the array.
* The arrangements may be output in any order.
*/
public class PermuteArray {
@shaaslam
shaaslam / PermuteString.java
Created February 9, 2018 22:28
Write a function permute that accepts a string as a parameter and outputs all possible rearrangements of the letters in that string. The arrangements may be output in any order.
package com.shaaslam.recurrsion;
/*
* Write a function permute that accepts a string as a parameter
* and outputs all possible rearrangements of the letters in that string.
* The arrangements may be output in any order.
*/
public class PermuteString {
public static void permute(String s) {
permuteHelper(s, "");