<commit_before>package leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * https://leetcode.com/problems/wiggle-subsequence/
 */
public class Problem376 {
    public int wiggleMaxLength(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        Map<String, Integer> memo = new HashMap<>();
        int a = wiggleMaxLength(nums, 1, 0, true, 1, memo);
        int b = wiggleMaxLength(nums, 1, 0, false, 1, memo);
        return Math.max(a, b);
    }

    private static int wiggleMaxLength(int[] nums, int idx, int prevIdx, boolean positive,
                                       int accu, Map<String, Integer> memo) {
        if (idx == nums.length) {
            return accu;
        }
        String key = idx + "|" + prevIdx + "|" + positive + "|" + accu;
        if (memo.containsKey(key)) {
            return memo.get(key);
        }
        int max = 0;
        if ((nums[idx] - nums[prevIdx] > 0 && positive) ||
            (nums[idx] - nums[prevIdx] < 0 && !positive)) {
            max = Math.max(max, wiggleMaxLength(nums, idx + 1, idx, !positive, accu + 1, memo));
        }
        max = Math.max(max, wiggleMaxLength(nums, idx + 1, prevIdx, positive, accu, memo));<commit_msg>Update problem 376<commit_after>package leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * https://leetcode.com/problems/wiggle-subsequence/
 */
public class Problem376 {
    public int wiggleMaxLength(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        Map<String, Integer> memo = new HashMap<>();
        int a = wiggleMaxLength(nums, 1, 0, true, memo);
        int b = wiggleMaxLength(nums, 1, 0, false, memo);
        return Math.max(a, b);
    }

    private static int wiggleMaxLength(int[] nums, int idx, int prevIdx, boolean positive,
                                       Map<String, Integer> memo) {
        if (idx == nums.length) {
            return 1;
        }
        String key = idx + "|" + prevIdx + "|" + positive;
        if (memo.containsKey(key)) {
            return memo.get(key);
        }
        int max = 0;
        if ((nums[idx] - nums[prevIdx] > 0 && positive) ||
            (nums[idx] - nums[prevIdx] < 0 && !positive)) {
            max = Math.max(max, wiggleMaxLength(nums, idx + 1, idx, !positive, memo) + 1);
        }
        max = Math.max(max, wiggleMaxLength(nums, idx + 1, prevIdx, positive, memo));
{'fraction_non_alphanumeric': 0.14350515463917526, 'fraction_numerical': 0.014845360824742268, 'mean_word_length': 2.021170610211706, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3297680', 'n_tokens_mistral': 842, 'n_tokens_neox': 787, 'n_words': 204}