This repository contains solutions to various data structure and algorithm problems implemented in Java and C++.
Problem Statement:
Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.
Examples:
-
Input: s = "egg", t = "add" Output: true
-
Input: s = "foo", t = "bar" Output: false
-
Input: s = "paper", t = "title" Output: true
Files:
IsomorphicString.java(Java implementation)IsomorphicString.cpp(C++ implementation)TestIsomorphicString.java(Test cases for Java)
Problem Statement:
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.
Examples:
-
Input: nums = [2, 7, 11, 15], target = 9 Output: [0, 1] (nums[0] + nums[1] = 2 + 7 = 9)
-
Input: nums = [3, 2, 4], target = 6 Output: [1, 2] (nums[1] + nums[2] = 2 + 4 = 6)
-
Input: nums = [3, 3], target = 6 Output: [0, 1] (nums[0] + nums[1] = 3 + 3 = 6)
Files:
TwoSum.java(Java implementation)TwoSum.cpp(C++ implementation)TestTwoSum.java(Test cases for Java)