qn1
import [Link];
public class PalindromeChecker {
public static boolean isPalindrome(String s) {
s = [Link]().replaceAll("[^a-z0-9]", "");
int i = 0, j = [Link]() - 1;
while (i < j) {
if ([Link](i) != [Link](j)) {
return false;
}
i++;
j--;
}
return true;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
String input = [Link]();
[Link](isPalindrome(input));
[Link]();
}
}
##
wcc-1-1
import [Link];
public class Solution {
public int singleNumber(int[] nums) {
int t=0;
for(int i=0;i<[Link];i++)
{
t^=nums[i];
}
return t;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// [Link]("Enter the numbers separated by spaces:");
String input = [Link](); // Get input as a single line
String[] inputArray = [Link](" "); // Split the input string by spaces
int[] nums = new int[[Link]];
for (int i = 0; i < [Link]; i++) {
nums[i] = [Link](inputArray[i]); // Convert each value to an
integer
}
Solution solution = new Solution();
int result = [Link](nums);
[Link](result);
}
}
##
wcc-4-hard
import [Link].*;
class Solution {
public int firstMissingPositive(int[] nums) {
int[] filterednums = [Link](nums).filter(n-> n > 0).toArray();
[Link](filterednums);
int target=1;
for(int n : filterednums)
{
if(n==target)
{
target++;
}
else if(n>target)
{
return target;
}
}
return target;
}
}
public class Main
{
public static void main(String[] args) {
Solution solution = new Solution();
Scanner scanner = new Scanner([Link]);
// Input the size of the array
int n = [Link]();
// Input the array elements
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = [Link]();
}
// Find the smallest missing positive integer
int result = [Link](nums);
[Link]("The smallest missing positive integer is: " + result);
}
}
##
wcc-5-hard
import [Link].*;
import [Link];
public class Solution {
public int calculate(String s) {
Stack<Integer> stack = new Stack<>();
int ans = 0;
int num = 0;
int sign = 1;
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if ([Link](ch)) {
num = num * 10 + (ch - '0');
} else if (ch == '+' || ch == '-') {
ans += num * sign;
num = 0;
sign = (ch == '-') ? -1 : 1;
} else if (ch == '(') {
[Link](ans);
[Link](sign);
ans = 0;
sign = 1;
} else if (ch == ')') {
ans += num * sign;
ans *= [Link](); // sign before '('
ans += [Link](); // result before '('
num = 0;
}
}
ans += num * sign;
return ans;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
String input = [Link]();
// Create an instance of Solution and process the input
Solution solution = new Solution();
int result = [Link](input);
[Link](result);
[Link]();
}
}
##
wcc-7-hard
import [Link].*;
public class Solution {
public int maxProfit(int[] prices) {
int sell1 = 0, sell2 = 0, buy1 = Integer.MIN_VALUE, buy2 =
Integer.MIN_VALUE;
for (int i = 0; i < [Link]; i++) {
buy1 = [Link](buy1, -prices[i]);
sell1 = [Link](sell1, buy1 + prices[i]);
buy2 = [Link](buy2, sell1 - prices[i]);
sell2 = [Link](sell2, buy2 + prices[i]);
}
return sell2;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Read the number of days (size of the prices array)
//[Link]("Enter the number of days: ");
int n = [Link]();
// Read the stock prices for each day
int[] prices = new int[n];
//[Link]("Enter the stock prices (space-separated): ");
for (int i = 0; i < n; i++) {
prices[i] = [Link]();
}
// Create an object of the Solution class
Solution solution = new Solution();
// Calculate and print the maximum profit
int maxProfit = [Link](prices);
[Link](maxProfit);
// Close the scanner
[Link]();
}
}
##
wcc-8-easy
import [Link].*;
public class Solution {
public int climbStairs(int n) {
if (n <= 3) return n;
int prev1 = 3;
int prev2 = 2;
int cur = 0;
for (int i = 3; i < n; i++) {
cur = prev1 + prev2;
prev2 = prev1;
prev1 = cur;
}
return cur;
}
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
Solution sol = new Solution();
int n = [Link]();
[Link]([Link](n));
[Link]();
}
}
##
wcc-8-med
import [Link].*;
public class Solution {
public int maxSubArray(int[] nums) {
int res = nums[0];
int total = 0;
for (int n : nums) {
if (total < 0) {
total = 0;
}
total += n;
res = [Link](res, total);
}
return res;
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String input = [Link]();
String[] inputArray = [Link](" ");
int[] nums = new int[[Link]];
for (int i = 0; i < [Link]; i++) {
nums[i] = [Link](inputArray[i]);
}
Solution sol = new Solution();
[Link]( [Link](nums));
[Link]();
}
}
##
wcc-8-hard
import [Link].*;
public class Solution {
public int maxPoints(int[][] points) {
int n = [Link];
if(n <= 2) return n; // 2 or less points can always form a line.
int ans = 2;
for(int[] a : points){
//Map<Double, Integer> for storing (slope, no of times 2 points
generate this slope.)
Map<Double, Integer> map = new HashMap<>();
for(int[] b : points){
if(a == b) continue; // dont measure slope for same points in
plane.
// if a is (x1, y1) and b is(x2, y2) then slope is (y2 - y1)/(x2 -
x1)
// a (a0, a1) & b is (b0, b1)
double slope = 0;
if(b[0] - a[0] == 0) slope = Double.POSITIVE_INFINITY;
else slope = (b[1] -a[1]) / (double)(b[0] - a[0]);
//[Link](slope, 0)+1 is adding 1 more point count for
that slope if we already had that slope.
// by default , 1 will be count of a new slope.
[Link](slope, [Link](slope, 1)+1);
ans = [Link](ans, [Link](slope));
}
}
//ans itself represnets max no of points forms a line
return ans;
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int[][] points = new int[n][2];
for (int i = 0; i < n; i++) {
points[i][0] = [Link]();
points[i][1] = [Link]();
}
Solution sol = new Solution();
[Link]([Link](points));
[Link]();
}
}
##
wcc-9-easy
import [Link].*;
public class Solution {
public int[] plusOne(int[] digits) {
for (int i = [Link] - 1; i >= 0; i--) {
if (digits[i] + 1 != 10) {
digits[i] += 1;
return digits;
}
digits[i] = 0;
}
int[] newDigits = new int[[Link] + 1];
newDigits[0] = 1;
return newDigits;
}
public static void main(String[] args)
{
Scanner scanner = new Scanner([Link]);
String[] input = [Link]().split(" ");
int[] digits = new int[[Link]];
for (int i = 0; i < [Link]; i++)
{
digits[i] = [Link](input[i]);
}
Solution solution = new Solution();
int[] result = [Link](digits);
[Link]("[");
for (int i = 0; i < [Link]; i++)
{
[Link](result[i]);
if (i < [Link] - 1)
{
[Link](",");
}
}
[Link]("]");
[Link]();
}
}
##
wcc-9-med
import [Link];
import [Link];
import [Link].*;
public class Solution {
public int countPrimes(int n) {
if(n <= 2) return 0;
boolean[] isPrime = new boolean[n];
[Link](isPrime, true);
isPrime[0] = false;
isPrime[1] = false;
for(int i = 2; i * i < n; i++){
if(isPrime[i]){
for(int j = i * i; j < n; j += i){
isPrime[j] = false;
}
}
}
int cnt = 0;
for(boolean prime: isPrime){
if(prime){
cnt++;
}
}
return cnt;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
//[Link]("Enter a number: ");
int n = [Link](); // Read user input
[Link]();
Solution sol = new Solution();
[Link]( [Link](n));
}
}
##
wcc-9-hard
import [Link].*;
import [Link].*;
enum Result {
TRUE, FALSE
}
public class Solution {
Result[][] memo;
public boolean isMatch(String text, String pattern) {
memo = new Result[[Link]() + 1][[Link]() + 1];
return dp(0, 0, text, pattern);
}
public boolean dp(int i, int j, String text, String pattern) {
if (memo[i][j] != null) {
return memo[i][j] == [Link];
}
boolean ans;
if (j == [Link]()){
ans = i == [Link]();
} else{
boolean first_match = (i < [Link]() &&
([Link](j) == [Link](i) ||
[Link](j) == '.'));
if (j + 1 < [Link]() && [Link](j+1) == '*'){
ans = (dp(i, j+2, text, pattern) ||
first_match && dp(i+1, j, text, pattern));
} else {
ans = first_match && dp(i+1, j+1, text, pattern);
}
}
memo[i][j] = ans ? [Link] : [Link];
return ans;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Get input string and pattern from user
//[Link]("Enter string s: ");
String s = [Link]();
//[Link]("Enter pattern p: ");
String p = [Link]();
Solution sol = new Solution();
// Print the result
[Link]([Link](s, p));
[Link]();
}
}
##
wcc-10-easy
import [Link].*;
public class Solution {
public boolean isAnagram(String s, String t) {
if ([Link]() != [Link]()) {
return false;
}
Map<Character, Integer> counter = new HashMap<>();
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
[Link](ch, [Link](ch, 0) + 1);
}
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if ( || [Link](ch) == 0) {
return false;
}
[Link](ch, [Link](ch) - 1);
}
return true;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
String s = [Link]().toLowerCase(); // Convert to lowercase for
consistency
String t = [Link]().toLowerCase();
Solution solution = new Solution();
boolean result = [Link](s, t);
// Print result
[Link](result);
[Link]();
}
}
##
wcc-10-med
import [Link].*;
public class Solution {
public int[] productExceptSelf(int[] nums) {
int[] output = new int[[Link]];
for (int i = 0; i < [Link]; i++) {
output[i] = 1;
}
int left = 1;
for (int i = 0; i < [Link]; i++) {
output[i] *= left;
left *= nums[i];
}
int right = 1;
for (int i = [Link] - 1; i >= 0; i--) {
output[i] *= right;
right *= nums[i];
}
return output;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Get input size
int n = [Link]();
// Get input array
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = [Link]();
}
Solution solution = new Solution();
int[] result = [Link](nums);
// Display the result
for (int num : result) {
[Link](num + " ");
}
[Link]();
}
}
##
wcc-10-hard
import [Link].*;
public class Solution {
public String numberToWords(int num) {
if(num == 0)
return "Zero";
String[] bigString = new String[]{"Thousand","Million","Billion"};
String result = numberToWordsHelper(num%1000);
num = num/1000;
if(num > 0 && num%1000>0){
result = numberToWordsHelper(num%1000) + "Thousand " + result;
}
num = num/1000;
if(num > 0 && num%1000>0){
result = numberToWordsHelper(num%1000) + "Million " + result;
}
num = num/1000;
if(num > 0){
result = numberToWordsHelper(num%1000) + "Billion " + result;
}
return [Link]();
}
public String numberToWordsHelper(int num){
String[] digitString = new String[]{"Zero", "One", "Two", "Three", "Four",
"Five", "Six", "Seven", "Eight", "Nine"};
String[] teenString = new String[]{"Ten", "Eleven", "Twelve", "Thirteen",
"Fourteen", "Fifteen", "Sixteen", "Seventeen","Eighteen", "Nineteen"};
String[] tenString = new String[]{"","","Twenty", "Thirty", "Forty", "Fifty",
"Sixty", "Seventy", "Eighty", "Ninety"};
String result = "";
if(num > 99){
result += digitString[num/100] + " Hundred ";
}
num = num % 100;
if(num < 20 && num > 9){
result += teenString[num%10]+" ";
}else{
if(num > 19){
result += tenString[num/10]+" ";
}
num = num % 10;
if(num > 0)
result += digitString[num]+" ";
}
return result;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
int num = [Link]();
// Convert number to words
Solution solution = new Solution();
String result = [Link](num);
// Display the output
[Link](result);
[Link]();
}
}
##
wcc-11-easy
import [Link].*;
public class Solution {
public int lengthOfLastWord(String s) {
int end = [Link]() - 1;
while (end >= 0 && [Link](end) == ' ') {
end--;
}
int start = end;
while (start >= 0 && [Link](start) != ' ') {
start--;
}
return end - start;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
String input = [Link]();
// Create Solution object and call the method
Solution solution = new Solution();
int length = [Link](input);
// Print the result
[Link](length);
}
}
##
wcc-11-med
import [Link].*;
import [Link];
public class Solution {
public void sortColors(int[] nums) {
HashMap<Integer, Integer> count = new HashMap<>();
[Link](0, 0);
[Link](1, 0);
[Link](2, 0);
for (int num : nums) {
[Link](num, [Link](num) + 1);
}
int idx = 0;
for (int color = 0; color < 3; color++) {
int freq = [Link](color);
for (int j = 0; j < freq; j++) {
nums[idx] = color;
idx++;
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Take input array size
//[Link]("Enter number of elements: ");
int n = [Link]();
int[] nums = new int[n];
// Take array elements as input
//[Link]("Enter elements (only 0, 1, or 2): ");
for (int i = 0; i < n; i++) {
nums[i] = [Link]();
}
// Sort colors
Solution solution = new Solution();
[Link](nums);
// Print the sorted array
[Link]([Link](nums));
}
}
##
wcc-11-hard
import [Link].*;
public class Solution {
public int candy(int[] ratings) {
int n = [Link];
int cnt = 0;
int[] candies = new int[n];
for (int i = 0; i < n; i++) candies[i] = 1;
for (int i = 1; i < n; i++)
if (ratings[i] > ratings[i - 1])
candies[i] = candies[i - 1] + 1;
for (int i = n - 1; i > 0; i--) {
if (ratings[i - 1] > ratings[i])
candies[i - 1] = [Link](candies[i] + 1, candies[i - 1]);
cnt += candies[i - 1];
}
return cnt + candies[n - 1];
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Taking runtime input
//[Link]("Enter number of children: ");
int n = [Link]();
int[] ratings = new int[n];
// [Link]("Enter ratings of children:");
for (int i = 0; i < n; i++) {
ratings[i] = [Link]();
}
Solution solution = new Solution();
int result = [Link](ratings);
[Link](result);
[Link]();
}
}
##
wcc-12-easy
import [Link].*;
public class Solution {
public int searchInsert(int[] nums, int target) {
int left = 0;
int right = [Link] - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (nums[mid] == target) {
return mid;
} else if (nums[mid] > target) {
right = mid - 1;
} else {
left = mid + 1;
}
}
return left;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Taking runtime input for the array
//[Link]("Enter number of elements: ");
int n = [Link]();
int[] nums = new int[n];
//[Link]("Enter sorted array elements:");
for (int i = 0; i < n; i++) {
nums[i] = [Link]();
}
// Taking runtime input for the target value
//[Link]("Enter target value: ");
int target = [Link]();
Solution solution = new Solution();
int result = [Link](nums, target);
[Link](result);
[Link]();
}
}
##
wcc-12-med
import [Link];
import [Link].*;
public class Solution {
public int coinChange(int[] coins, int amount) {
int[] minCoins = new int[amount + 1];
[Link](minCoins, amount + 1);
minCoins[0] = 0;
for (int i = 1; i <= amount; i++) {
for (int j = 0; j < [Link]; j++) {
if (i - coins[j] >= 0) {
minCoins[i] = [Link](minCoins[i], 1 + minCoins[i -
coins[j]]);
}
}
}
return minCoins[amount] != amount + 1 ? minCoins[amount] : -1;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// User input for coin denominations
//[Link]("Enter the number of coins:");
int n = [Link]();
int[] coins = new int[n];
//[Link]("Enter the coin values:");
for (int i = 0; i < n; i++) {
coins[i] = [Link]();
}
// User input for amount
//[Link]("Enter the amount:");
int amount = [Link]();
Solution solution = new Solution();
int result = [Link](coins, amount);
[Link](result);
}
}
##
wcc-12-hard
import [Link].*;
public class Solution {
public List<String> findAllConcatenatedWordsInADict(String[] words) {
Set<String> s = new HashSet<>();
List<String> concatenateWords = new ArrayList<>();
for(String word : words)
[Link](word);
for(String word : words) {
if(checkConcatenate(word, s) == true)
[Link](word);
}
return concatenateWords;
}
public boolean checkConcatenate(String word, Set<String> s) {
for(int i = 1; i < [Link](); i++) {
String prefixWord = [Link](0, i);
String suffixWord = [Link](i, [Link]());
if([Link](prefixWord) && ([Link](suffixWord) ||
checkConcatenate(suffixWord, s)))
return true;
}
return false;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Take input for the number of words
//[Link]("Enter the number of words:");
int n = [Link]();
[Link](); // Consume newline character
// Take input for words
String[] words = new String[n];
//[Link]("Enter the words:");
for (int i = 0; i < n; i++) {
words[i] = [Link]();
}
// Process the input and find concatenated words
Solution solution = new Solution();
List<String> result = [Link](words);
// Print output in the desired format with double quotes
//[Link]("Output:");
[Link]("[");
for (int i = 0; i < [Link](); i++) {
[Link]("\"" + [Link](i) + "\"");
if (i < [Link]() - 1) {
[Link](", ");
}
}
[Link]("]");
[Link]();
}
}
##
wcc-13-easy
import [Link].*;
public class Solution {
public boolean hasMatch(String s, String p) {
int index = [Link]('*');
int firstpos = [Link]([Link](0, index));
int secondpos = [Link]([Link](index + 1), firstpos + index);
if (firstpos != -1 && secondpos != -1) {
return true;
}
return false;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Take input for the string s and the pattern p
//[Link]("Enter the string s:");
String s = [Link]();
//[Link]("Enter the pattern p (with exactly one '*'):");
String p = [Link]();
// Process the input and check if the pattern can be a substring
Solution solution = new Solution();
boolean result = [Link](s, p);
// Print the output based on the result
if (result) {
[Link]("true");
} else {
[Link]("false");
}
[Link]();
}
}
##
wcc-13-med
import [Link].*;
public class Solution {
public void rotate(int[] nums, int k) {
k %= [Link];
reverse(nums, 0, [Link] - 1);
reverse(nums, 0, k - 1);
reverse(nums, k, [Link] - 1);
}
private void reverse(int[] nums, int left, int right) {
while (left < right) {
int temp = nums[left];
nums[left] = nums[right];
nums[right] = temp;
left++;
right--;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Input for the array size and the array elements
//[Link]("Enter the size of the array:");
int n = [Link]();
int[] nums = new int[n];
//[Link]("Enter the elements of the array:");
for (int i = 0; i < n; i++) {
nums[i] = [Link]();
}
// Input for the number of rotations
//[Link]("Enter the number of rotations (k):");
int k = [Link]();
// Create Solution object and rotate the array
Solution solution = new Solution();
[Link](nums, k);
// Print the rotated array
//[Link]("Rotated Array:");
for (int num : nums) {
[Link](num + " ");
}
[Link]();
}
}
##
wcc-13-hard
import [Link].*;
public class Solution {
public boolean isNumber(String s) {
boolean isdot = false, ise = false, nums = false;
for (int i = 0; i < [Link](); i++) {
char c = [Link](i);
if ([Link](c)) nums = true;
else if (c == '+' || c == '-') {
if (i > 0 && [Link](i - 1) != 'e' && [Link](i - 1) != 'E')
return false;
}
else if (c == 'e' || c == 'E') {
if (ise || !nums) return false;
ise = true;
nums = false;
}
else if (c == '.') {
if (isdot || ise) return false;
isdot = true;
}
else return false;
}
return nums;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Input string to be checked
//[Link]("Enter a string to check if it's a valid number:");
String input = [Link]();
// Create Solution object and check the input string
Solution solution = new Solution();
boolean result = [Link](input);
// Output result
if (result) {
[Link]("true");
} else {
[Link]("false");
}
[Link]();
}
}
##
wcc-14-easy
import [Link].*;
public class Solution {
public int findMaxConsecutiveOnes(int[] nums) {
int res = 0;
int count = 0;
for (int n : nums) {
if (n == 0) {
count = 0;
} else {
count++;
}
if (res < count) {
res = count;
}
}
return res;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
String input = [Link]();
String[] inputStrings = [Link](" ");
int[] nums = new int[[Link]];
for (int i = 0; i < [Link]; i++) {
nums[i] = [Link](inputStrings[i]);
}
Solution solution = new Solution();
int result = [Link](nums);
[Link](result);
[Link]();
}
}
##
wcc-14-med
import [Link].*;
public class Solution {
public int maxProduct(int[] nums) {
int res = Integer.MIN_VALUE;
for (int n : nums) {
res = [Link](res, n);
}
int curMax = 1, curMin = 1;
for (int n : nums) {
int temp = curMax * n;
curMax = [Link](temp, [Link](curMin * n, n));
curMin = [Link](temp, [Link](curMin * n, n));
res = [Link](res, curMax);
}
return res;
}
public static void main(String[] args)
{
Scanner scanner = new Scanner([Link]);
String input = [Link]();
String[] inputStrings = [Link](" ");
int[] nums = new int[[Link]];
for (int i = 0; i < [Link]; i++)
{
nums[i] = [Link](inputStrings[i]);
}
Solution solution = new Solution();
int result = [Link](nums);
[Link](result);
[Link]();
}
##
wcc-14-hard
import [Link].*;
public class Solution {
public int longestValidParentheses(String s) {
Stack<Integer> stack = new Stack<>();
[Link](-1);
int max_len = 0;
for (int i = 0; i < [Link](); i++) {
if ([Link](i) == '(') {
[Link](i);
} else {
[Link]();
if ([Link]()) {
[Link](i);
} else {
max_len = [Link](max_len, i - [Link]());
}
}
}
return max_len;
}
public static void main(String[] args) {
Solution solution = new Solution();
[Link] scanner = new [Link]([Link]);
String s = [Link]().trim();
int result = [Link](s);
[Link](result);
[Link]();
}
}
##
wcc-15-easy
import [Link].*;
public class Solution {
public List<Boolean>kidsWithcandies(int[] candies, int extraCandies) {
int maxCandies = 0;
for (int candy : candies) {
maxCandies = [Link](maxCandies, candy);
}
List<Boolean> result = new ArrayList<>();
for (int candy : candies) {
if (candy + extraCandies >= maxCandies) {
[Link](true);
} else {
[Link](false);
}
}
return result;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
int n = [Link]();
int[] candies = new int[n];
for (int i = 0; i < n; i++) {
candies[i] = [Link]();
}
int extraCandies = [Link]();
// Compute the result
Solution sol = new Solution();
List<Boolean> result = [Link](candies, extraCandies);
// Display the result
[Link](result);
[Link]();
}
}
##
wcc-15-med
import [Link];
public class Solution {
public int longestCommonSubsequence(String text1, String text2) {
int[] dp = new int[[Link]()];
int longest = 0;
for (char c : [Link]()) {
int curLength = 0;
for (int i = 0; i < [Link]; i++) {
if (curLength < dp[i]) {
curLength = dp[i];
} else if (c == [Link](i)) {
dp[i] = curLength + 1;
longest = [Link](longest, curLength + 1);
}
}
}
return longest;
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
String text1 = [Link]();
String text2 = [Link]();
Solution sol = new Solution();
// Compute and display the LCS length
int result = [Link](text1, text2);
[Link](result);
[Link]();
}
}
##
wcc-15-hard
import [Link].*;
public class Solution {
public int numDistinct(String s, String t) {
int m = [Link](), n = [Link]();
int[][] dp = new int[m + 1][n + 1];
for(int i = 0; i < m; i ++){
dp[i][0] = 1;
}
for(int i = 1; i <= m; i ++){
for(int j = 1; j <= n; j ++){
if([Link](i - 1) == [Link](j - 1)){
dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
}else{
dp[i][j] = dp[i - 1][j];
}
}
}
return dp[m][n];
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
String s = [Link]();
String t = [Link]();
Solution solution = new Solution();
int result = [Link](s, t);
[Link](result);
[Link]();
}
}