<commit_before>import unittest
"""
Given a sorted array of integers, return the number of distinct absolute values
among the elements of the array. The input can contain duplicate values.
Input: -3 -2 0 3 4 5
Output: 5
"""

"""
Approach:
1. Scan using two pointers.
2. Take care of duplicates and same absolute values.
"""


def absolute_distinct_count(sorted_list):

    left = 0
    right = len(sorted_list) - 1
    prev_distinct = None
    count = 0

    while left <= right:
        if prev_distinct is not None and abs(sorted_list[left]) == prev_distinct:
            left += 1
        elif prev_distinct is not None and abs(sorted_list[right]) == prev_distinct:
            right -= 1
        elif abs(sorted_list[left]) == abs(sorted_list[right]):
            prev_distinct = abs(sorted_list[left])
            count += 1
            left += 1
            right -= 1
        elif abs(sorted_list[left]) > abs(sorted_list[right]):
            prev_distinct = abs(sorted_list[left])
            count += 1
            left += 1
        else:
            prev_distinct = abs(sorted_list[right])
            count += 1
            right -= 1

    return count


class TestAbsoluteDistinctCounts(unittest.TestCase):

    def test_absolute_distinct_counts(self):
        sorted_list = [-3, -2, 0, 3, 4, 5]
        self.assertEqual(absolute_distinct_count(sorted_list), 5)
        sorted_list = [-1, -1, -1, -1, 0, 1, 1, 1, 1]
        self.assertEqual(absolute_distinct_count(sorted_list), 2)
        sorted_list = [-1, -1, -1, -1, 0]
        self.assertEqual(absolute_distinct_count(sorted_list), 2)
        sorted_list = [0, 0, 0]
        self.assertEqual(absolute_distinct_count(sorted_list), 1)
<commit_msg>Updated logic<commit_after>import unittest
"""
Given a sorted array of integers, return the number of distinct absolute values
among the elements of the array. The input can contain duplicate values.
Input: -3 -2 0 3 4 5
Output: 5
"""

"""
Approach:
1. Scan using two pointers.
2. Take care of duplicates and same absolute values.
"""


def absolute_distinct_count(sorted_list):

    left = 0
    right = len(sorted_list) - 1
    prev_distinct = None
    count = 0

    while left <= right:
        lval = abs(sorted_list[left])
        rval = abs(sorted_list[right])
        if lval == rval:
            if prev_distinct is None or prev_distinct != lval:
                prev_distinct = lval
                count += 1
            left += 1
            right -= 1
        elif lval > rval:
            if prev_distinct is None or prev_distinct != lval:
                prev_distinct = lval
                count += 1
            left += 1
        else:
            if prev_distinct is None or prev_distinct != rval:
                prev_distinct = rval
                count += 1
            right -= 1

    return count


class TestAbsoluteDistinctCounts(unittest.TestCase):

    def test_absolute_distinct_counts(self):
        sorted_list = [-3, -2, 0, 3, 4, 5]
        self.assertEqual(absolute_distinct_count(sorted_list), 5)
        sorted_list = [-1, -1, -1, -1, 0, 1, 1, 1, 1]
        self.assertEqual(absolute_distinct_count(sorted_list), 2)
        sorted_list = [-1, -1, -1, -1, 0]
        self.assertEqual(absolute_distinct_count(sorted_list), 2)
        sorted_list = [0, 0, 0]
        self.assertEqual(absolute_distinct_count(sorted_list), 1)

{'fraction_non_alphanumeric': 0.09943603443158207, 'fraction_numerical': 0.027901454437518552, 'mean_word_length': 2.2623426911907067, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4717834', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1044, 'n_words': 312}