Skip to content

Conversation

@codeflash-ai
Copy link
Contributor

@codeflash-ai codeflash-ai bot commented Jan 16, 2026

📄 40,778% (407.78x) speedup for longest_increasing_subsequence_length in code_to_optimize/sample_code.py

⏱️ Runtime : 859 milliseconds 2.10 milliseconds (best of 79 runs)

📝 Explanation and details

The optimized code achieves a 408x speedup by replacing the O(n²) dynamic programming algorithm with an O(n log n) patience sorting approach using binary search.

Key algorithmic change:

  • Original approach: Nested loops comparing every element with all previous elements (O(n²) complexity). The line profiler shows the inner loop executed 1.6M times, consuming 23.2% of total runtime, with comparison operations taking another 33.4%.
  • Optimized approach: Maintains a sorted tails array where tails[k] stores the smallest tail value of any increasing subsequence of length k+1. For each element, uses bisect.bisect_left() to find its insertion position in O(log n) time.

Why this is faster:

  1. Eliminates nested iteration: Instead of comparing each element with all previous elements (1.6M comparisons in the profiler), we perform just one binary search per element (~5,800 searches for ~5,800 elements).
  2. Leverages optimized C implementation: Python's bisect module is implemented in C and highly optimized for sorted list operations.
  3. Reduces memory operations: No repeated array indexing in tight loops. The tails list grows incrementally and stays small (max length = LIS length, not input length).

Performance characteristics from test results:

  • Small arrays (< 10 elements): Modest 20-150% speedup due to overhead being comparable to the O(n²) work.
  • Medium arrays (~30-100 elements): 2,000-23,000% speedup as the quadratic penalty becomes significant.
  • Large arrays (400-500 elements): 31,000-96,000% speedup - the profiler shows original runtime of 3.66s vs optimized 16.7ms for the same workload.
  • Worst-case patterns: Descending sequences show 31,707% speedup (was O(n²) comparisons with no updates, now O(n log n) searches).

Impact considerations:
The optimization maintains identical correctness (handles integers, floats, negatives, duplicates, edge cases) while dramatically improving performance on any input size > ~10 elements. Given the massive speedup on realistic data sizes, this change would benefit any workload calling this function repeatedly or on non-trivial arrays.

Correctness verification report:

Test Status
⚙️ Existing Unit Tests 21 Passed
🌀 Generated Regression Tests 47 Passed
⏪ Replay Tests 🔘 None Found
🔎 Concolic Coverage Tests 🔘 None Found
📊 Tests Coverage 100.0%
⚙️ Click to see Existing Unit Tests
Test File::Test Function Original ⏱️ Optimized ⏱️ Speedup
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_all_same_elements 15.5μs 10.2μs 52.4%✅
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_alternating_sequence 30.2μs 11.2μs 168%✅
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_classic_example 29.0μs 11.2μs 159%✅
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_empty_array 1.01μs 927ns 9.17%✅
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_float_values 25.0μs 11.5μs 118%✅
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_longer_sequence 73.5μs 13.1μs 459%✅
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_negative_numbers 23.0μs 10.9μs 112%✅
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_single_element 11.8μs 9.40μs 25.5%✅
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_strictly_decreasing 15.4μs 10.4μs 48.8%✅
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_strictly_increasing 22.6μs 10.6μs 114%✅
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_two_elements_decreasing 12.6μs 9.77μs 29.5%✅
test_numba_jit_code.py::TestLongestIncreasingSubsequenceLength.test_two_elements_increasing 14.2μs 9.61μs 47.3%✅
🌀 Click to see Generated Regression Tests
import numpy as np

# imports
from code_to_optimize.sample_code import longest_increasing_subsequence_length

# Test Suite for longest_increasing_subsequence_length function
# This suite comprehensively tests the function across basic, edge, and large-scale scenarios


# ============================================================================
# BASIC TEST CASES
# ============================================================================
# These tests verify fundamental functionality under normal conditions


def test_basic_single_element():
    """Test with a single element array - should return 1"""
    arr = np.array([5], dtype=np.int64)
    codeflash_output = longest_increasing_subsequence_length(arr)  # 10.9μs -> 9.04μs (21.0% faster)


def test_basic_two_elements_increasing():
    """Test with two elements in increasing order - should return 2"""
    arr = np.array([1, 2], dtype=np.int64)
    codeflash_output = longest_increasing_subsequence_length(arr)  # 13.7μs -> 9.46μs (44.4% faster)


def test_basic_two_elements_decreasing():
    """Test with two elements in decreasing order - should return 1"""
    arr = np.array([5, 3], dtype=np.int64)
    codeflash_output = longest_increasing_subsequence_length(arr)  # 12.1μs -> 9.61μs (26.0% faster)


def test_basic_simple_increasing_sequence():
    """Test with a simple strictly increasing sequence - should return 5"""
    arr = np.array([1, 2, 3, 4, 5], dtype=np.int64)
    codeflash_output = longest_increasing_subsequence_length(arr)  # 21.7μs -> 10.3μs (111% faster)


def test_basic_simple_decreasing_sequence():
    """Test with a simple strictly decreasing sequence - each element forms LIS of length 1"""
    arr = np.array([5, 4, 3, 2, 1], dtype=np.int64)
    codeflash_output = longest_increasing_subsequence_length(arr)  # 14.9μs -> 10.1μs (48.1% faster)


def test_basic_mixed_sequence_classic():
    """Test with the classic example [3, 10, 2, 1, 20]"""
    arr = np.array([3, 10, 2, 1, 20], dtype=np.int64)
    # LIS is [3, 10, 20] with length 3
    codeflash_output = longest_increasing_subsequence_length(arr)  # 18.6μs -> 10.5μs (77.0% faster)


def test_basic_mixed_sequence_another():
    """Test with another mixed sequence [1, 3, 6, 4, 10, 2, 5]"""
    arr = np.array([1, 3, 6, 4, 10, 2, 5], dtype=np.int64)
    # LIS is [1, 3, 4, 10] or [1, 3, 6, 10] with length 4
    codeflash_output = longest_increasing_subsequence_length(arr)  # 26.6μs -> 10.9μs (144% faster)


def test_basic_with_duplicates():
    """Test with duplicate values - duplicates should not extend the sequence"""
    arr = np.array([1, 2, 2, 3, 4], dtype=np.int64)
    # LIS is [1, 2, 3, 4] with length 4 (duplicates don't count as increasing)
    codeflash_output = longest_increasing_subsequence_length(arr)  # 21.1μs -> 10.3μs (104% faster)


def test_basic_with_negative_numbers():
    """Test with negative integers"""
    arr = np.array([-5, -3, -1, 0, 2, 4], dtype=np.int64)
    codeflash_output = longest_increasing_subsequence_length(arr)  # 25.9μs -> 10.6μs (145% faster)


def test_basic_with_mixed_negative_positive():
    """Test with mix of negative and positive numbers"""
    arr = np.array([-2, 1, -1, 3, 0, 5], dtype=np.int64)
    # One possible LIS: [-2, 1, 3, 5] with length 4
    codeflash_output = longest_increasing_subsequence_length(arr)  # 23.5μs -> 10.6μs (121% faster)


def test_basic_float_array():
    """Test with floating point numbers"""
    arr = np.array([1.5, 2.3, 0.5, 3.1, 1.8, 4.2], dtype=np.float64)
    # One possible LIS: [1.5, 2.3, 3.1, 4.2] with length 4
    codeflash_output = longest_increasing_subsequence_length(arr)  # 23.4μs -> 11.1μs (110% faster)


def test_basic_float_with_small_differences():
    """Test with floating point numbers with small differences"""
    arr = np.array([1.0, 1.1, 1.05, 1.2, 1.15], dtype=np.float64)
    # LIS is [1.0, 1.1, 1.2] with length 3
    codeflash_output = longest_increasing_subsequence_length(arr)  # 20.7μs -> 11.1μs (85.7% faster)


# ============================================================================
# EDGE TEST CASES
# ============================================================================
# These tests evaluate behavior under extreme or unusual conditions


def test_edge_empty_array():
    """Test with an empty array - should return 0"""
    arr = np.array([], dtype=np.int64)
    codeflash_output = longest_increasing_subsequence_length(arr)  # 973ns -> 855ns (13.8% faster)


def test_edge_all_same_elements():
    """Test array where all elements are identical - should return 1"""
    arr = np.array([5, 5, 5, 5, 5], dtype=np.int64)
    codeflash_output = longest_increasing_subsequence_length(arr)  # 14.8μs -> 10.1μs (46.2% faster)


def test_edge_very_large_number():
    """Test with very large integer values"""
    arr = np.array([1000000000, 2000000000, 500000000], dtype=np.int64)
    # LIS is [1000000000, 2000000000] with length 2
    codeflash_output = longest_increasing_subsequence_length(arr)  # 14.2μs -> 10.00μs (42.2% faster)


def test_edge_very_small_negative_number():
    """Test with very small negative integer values"""
    arr = np.array([-2000000000, -1000000000, -500000000], dtype=np.int64)
    codeflash_output = longest_increasing_subsequence_length(arr)  # 15.6μs -> 9.74μs (60.2% faster)


def test_edge_alternating_up_down():
    """Test with alternating increasing and decreasing pattern"""
    arr = np.array([1, 5, 2, 6, 3, 7, 4], dtype=np.int64)
    # LIS could be [1, 2, 3, 4] or [1, 2, 3, 7] or [1, 2, 6, 7] etc with length 4
    codeflash_output = longest_increasing_subsequence_length(arr)  # 26.8μs -> 11.0μs (145% faster)


def test_edge_sawtooth_pattern():
    """Test with a sawtooth pattern (up, down, up, down)"""
    arr = np.array([1, 10, 2, 9, 3, 8, 4, 7, 5, 6], dtype=np.int64)
    # LIS is [1, 2, 3, 4, 5, 6] with length 6
    codeflash_output = longest_increasing_subsequence_length(arr)  # 38.7μs -> 11.7μs (229% faster)


def test_edge_single_peak():
    """Test array that increases to a peak then decreases"""
    arr = np.array([1, 2, 3, 4, 5, 4, 3, 2, 1], dtype=np.int64)
    # LIS is [1, 2, 3, 4, 5] with length 5
    codeflash_output = longest_increasing_subsequence_length(arr)  # 31.7μs -> 11.5μs (175% faster)


def test_edge_single_valley():
    """Test array that decreases to a valley then increases"""
    arr = np.array([5, 4, 3, 2, 1, 2, 3, 4, 5], dtype=np.int64)
    # LIS is [1, 2, 3, 4, 5] with length 5
    codeflash_output = longest_increasing_subsequence_length(arr)  # 30.1μs -> 11.3μs (165% faster)


def test_edge_two_increasing_at_start():
    """Test array with increasing elements at start, then all smaller"""
    arr = np.array([1, 2, 3, 1, 2], dtype=np.int64)
    # LIS is [1, 2, 3] with length 3
    codeflash_output = longest_increasing_subsequence_length(arr)  # 18.8μs -> 10.5μs (79.6% faster)


def test_edge_increasing_at_end():
    """Test array with small values, then large increasing sequence at end"""
    arr = np.array([1, 1, 1, 1, 2, 3, 4, 5], dtype=np.int64)
    # LIS is [1, 2, 3, 4, 5] with length 5
    codeflash_output = longest_increasing_subsequence_length(arr)  # 29.8μs -> 11.2μs (167% faster)


def test_edge_float_zero_values():
    """Test with floating point zero values"""
    arr = np.array([0.0, 0.0, 1.0, 2.0, 0.0, 3.0], dtype=np.float64)
    # LIS is [0.0, 1.0, 2.0, 3.0] with length 4
    codeflash_output = longest_increasing_subsequence_length(arr)  # 22.6μs -> 11.0μs (105% faster)


def test_edge_float_negative_zero():
    """Test with floating point negative and positive zero"""
    arr = np.array([-0.0, 0.0, 1.0], dtype=np.float64)
    # In IEEE 754, -0.0 == 0.0, so this is still an increasing sequence
    codeflash_output = longest_increasing_subsequence_length(arr)  # 15.3μs -> 10.5μs (45.8% faster)


def test_edge_float_very_small_positive():
    """Test with very small positive floating point values"""
    arr = np.array([1e-10, 2e-10, 0.5e-10, 3e-10], dtype=np.float64)
    # LIS is [0.5e-10, 1e-10, 2e-10, 3e-10] or [1e-10, 2e-10, 3e-10]
    codeflash_output = longest_increasing_subsequence_length(arr)  # 17.8μs -> 10.8μs (64.0% faster)


def test_edge_float_very_small_negative():
    """Test with very small negative floating point values"""
    arr = np.array([-3e-10, -1e-10, -2e-10, 0.0], dtype=np.float64)
    # LIS is [-3e-10, -2e-10, -1e-10, 0.0] with length 4
    codeflash_output = longest_increasing_subsequence_length(arr)  # 18.2μs -> 10.5μs (73.9% faster)


def test_edge_all_zeros():
    """Test array with all zero values"""
    arr = np.array([0, 0, 0, 0], dtype=np.int64)
    # No strictly increasing sequence can be formed, max is 1
    codeflash_output = longest_increasing_subsequence_length(arr)  # 13.7μs -> 10.0μs (36.4% faster)


def test_edge_negative_to_positive_crossing():
    """Test crossing from negative to positive"""
    arr = np.array([-10, -5, 0, 5, 10], dtype=np.int64)
    codeflash_output = longest_increasing_subsequence_length(arr)  # 21.8μs -> 10.3μs (112% faster)


def test_edge_descending_with_one_increase():
    """Test mostly descending array with one increase"""
    arr = np.array([10, 9, 8, 2, 11, 7, 6], dtype=np.int64)
    # LIS could be [8, 11] or [2, 11] with length 2
    codeflash_output = longest_increasing_subsequence_length(arr)  # 21.4μs -> 10.8μs (97.3% faster)


def test_edge_int32_dtype():
    """Test with int32 dtype"""
    arr = np.array([1, 3, 2, 4, 5], dtype=np.int32)
    # LIS is [1, 3, 4, 5] or [1, 2, 4, 5] with length 4
    codeflash_output = longest_increasing_subsequence_length(arr)  # 21.9μs -> 10.8μs (103% faster)


def test_edge_float32_dtype():
    """Test with float32 dtype"""
    arr = np.array([1.5, 2.5, 1.8, 3.5], dtype=np.float32)
    # LIS is [1.5, 2.5, 3.5] with length 3
    codeflash_output = longest_increasing_subsequence_length(arr)  # 18.7μs -> 10.9μs (71.3% faster)


# ============================================================================
# LARGE SCALE TEST CASES
# ============================================================================
# These tests assess performance and scalability with larger data samples


def test_large_scale_ascending_sequence():
    """Test with a large ascending sequence (performance check)"""
    # Create an ascending array of size 500
    arr = np.arange(500, dtype=np.int64)
    # The entire array is a strictly increasing sequence
    codeflash_output = longest_increasing_subsequence_length(arr)  # 95.0ms -> 177μs (53409% faster)


def test_large_scale_descending_sequence():
    """Test with a large descending sequence (performance check)"""
    # Create a descending array of size 500
    arr = np.arange(500, 0, -1, dtype=np.int64)
    # Each element forms its own LIS, maximum length is 1
    codeflash_output = longest_increasing_subsequence_length(arr)  # 25.2ms -> 79.2μs (31707% faster)


def test_large_scale_random_sequence():
    """Test with a large random sequence (performance check)"""
    # Create a pseudo-random array using a fixed seed for reproducibility
    np.random.seed(42)
    arr = np.random.randint(0, 1000, size=500, dtype=np.int64)
    # Execute the function and verify it returns a reasonable result
    codeflash_output = longest_increasing_subsequence_length(arr)
    result = codeflash_output  # 45.2ms -> 134μs (33448% faster)


def test_large_scale_repeated_pattern():
    """Test with a large repeated pattern"""
    # Create an array with repeating pattern [1, 2, 3, 1, 2, 3, ...]
    pattern = np.array([1, 2, 3], dtype=np.int64)
    arr = np.tile(pattern, 100)  # Repeat pattern 100 times -> 300 elements
    # LIS should be [1, 2, 3] with length 3
    codeflash_output = longest_increasing_subsequence_length(arr)  # 13.6ms -> 59.5μs (22796% faster)


def test_large_scale_zigzag_pattern():
    """Test with large zigzag pattern"""
    # Create a zigzag: goes up then down, repeatedly
    arr = np.array([], dtype=np.int64)
    for i in range(50):
        # Each cycle: increase from i*10 to (i+1)*10, then decrease
        arr = np.append(arr, np.arange(i * 10, (i + 1) * 10 + 1, dtype=np.int64))
        arr = np.append(arr, np.arange((i + 1) * 10 - 1, i * 10 - 1, -1, dtype=np.int64))

    codeflash_output = longest_increasing_subsequence_length(arr)
    result = codeflash_output  # 343ms -> 357μs (96066% faster)


def test_large_scale_float_random():
    """Test with large array of random floating point numbers"""
    np.random.seed(123)
    arr = np.random.random(500).astype(np.float64)
    # Execute the function and verify result is reasonable
    codeflash_output = longest_increasing_subsequence_length(arr)
    result = codeflash_output  # 44.9ms -> 136μs (32846% faster)


def test_large_scale_mostly_increasing_with_noise():
    """Test with mostly increasing sequence with some noise (decreases)"""
    # Create mostly increasing array: [0, 1, 2, ..., 400] with random decreases
    arr = np.arange(400, dtype=np.int64)
    # Add some noise: randomly decrease some positions
    np.random.seed(456)
    noise_indices = np.random.choice(400, size=50, replace=False)
    for idx in noise_indices:
        arr[idx] = max(0, arr[idx] - np.random.randint(1, 20))

    codeflash_output = longest_increasing_subsequence_length(arr)
    result = codeflash_output  # 57.2ms -> 126μs (45053% faster)


def test_large_scale_heavily_duplicated():
    """Test with a large array containing mostly duplicate values"""
    # Create array: [1]*100 + [2]*100 + [3]*100 + [4]*100
    arr = np.concatenate(
        [
            np.ones(100, dtype=np.int64),
            np.ones(100, dtype=np.int64) * 2,
            np.ones(100, dtype=np.int64) * 3,
            np.ones(100, dtype=np.int64) * 4,
        ]
    )
    # LIS should be [1, 2, 3, 4] with length 4
    codeflash_output = longest_increasing_subsequence_length(arr)  # 33.2ms -> 72.3μs (45851% faster)


def test_large_scale_two_increasing_sequences():
    """Test with two separate increasing sequences"""
    # First increasing sequence [1, 2, ..., 200]
    # Then decreasing to 1, then second sequence [1, 2, ..., 200]
    seq1 = np.arange(1, 201, dtype=np.int64)
    seq2 = np.arange(200, 0, -1, dtype=np.int64)
    seq3 = np.arange(1, 201, dtype=np.int64)
    arr = np.concatenate([seq1, seq2, seq3])

    codeflash_output = longest_increasing_subsequence_length(arr)
    result = codeflash_output  # 81.4ms -> 190μs (42575% faster)


def test_large_scale_geometric_progression():
    """Test with geometric progression values"""
    # Create geometric sequence: 1, 2, 4, 8, 16, ..., 2^249 (but capped)
    arr = np.array([2**i for i in range(30)], dtype=np.int64)
    # Entire array is strictly increasing
    codeflash_output = longest_increasing_subsequence_length(arr)  # 358μs -> 15.9μs (2160% faster)


def test_large_scale_arithmetic_progression_mixed():
    """Test with mixed arithmetic progressions"""
    # Sequence: 1, 3, 5, 7, ... (odd) mixed with 2, 4, 6, 8, ... (even)
    odds = np.arange(1, 300, 2, dtype=np.int64)
    evens = np.arange(2, 300, 2, dtype=np.int64)
    # Interleave them in a complex way
    arr = np.concatenate([odds, evens])

    codeflash_output = longest_increasing_subsequence_length(arr)
    result = codeflash_output  # 24.9ms -> 95.2μs (26061% faster)


def test_large_scale_near_max_int64():
    """Test with values near the maximum int64"""
    max_int64 = np.iinfo(np.int64).max
    arr = np.array(
        [max_int64 - 1000, max_int64 - 500, max_int64 - 100, max_int64 - 50, max_int64 - 10, max_int64 - 1],
        dtype=np.int64,
    )
    # Array is strictly increasing
    codeflash_output = longest_increasing_subsequence_length(arr)  # 26.2μs -> 10.4μs (153% faster)


def test_large_scale_near_min_int64():
    """Test with values near the minimum int64"""
    min_int64 = np.iinfo(np.int64).min
    arr = np.array([min_int64 + 1, min_int64 + 50, min_int64 + 100, min_int64 + 500, min_int64 + 1000], dtype=np.int64)
    # Array is strictly increasing
    codeflash_output = longest_increasing_subsequence_length(arr)  # 21.2μs -> 10.1μs (110% faster)


def test_large_scale_float_infinity_values():
    """Test with very large floating point values approaching infinity"""
    arr = np.array([1e100, 1e150, 1e200, 1e250, 1e300], dtype=np.float64)
    # Array is strictly increasing
    codeflash_output = longest_increasing_subsequence_length(arr)  # 22.5μs -> 10.7μs (111% faster)


def test_large_scale_float_very_close_values():
    """Test with floating point values very close to each other"""
    arr = np.array([1.0, 1.0 + 1e-15, 1.0 + 2e-15, 1.0 + 3e-15], dtype=np.float64)
    # Check if these values are distinguishable in floating point arithmetic
    codeflash_output = longest_increasing_subsequence_length(arr)
    result = codeflash_output  # 19.1μs -> 10.4μs (82.9% faster)


def test_large_scale_performance_with_500_elements():
    """Comprehensive performance test with 500 elements"""
    # Create a challenging test case: nearly increasing with local fluctuations
    np.random.seed(789)
    base_array = np.arange(500, dtype=np.float64)
    # Add small random noise
    noise = np.random.normal(0, 0.1, 500)
    arr = (base_array + noise).astype(np.float64)

    # The function should complete quickly and return a reasonable result
    codeflash_output = longest_increasing_subsequence_length(arr)
    result = codeflash_output  # 93.6ms -> 178μs (52311% faster)


# codeflash_output is used to check that the output of the original code is the same as that of the optimized code.

To edit these changes git checkout codeflash/optimize-longest_increasing_subsequence_length-mkgfjtjc and push.

Codeflash Static Badge

The optimized code achieves a **408x speedup** by replacing the O(n²) dynamic programming algorithm with an O(n log n) patience sorting approach using binary search.

**Key algorithmic change:**
- **Original approach**: Nested loops comparing every element with all previous elements (O(n²) complexity). The line profiler shows the inner loop executed 1.6M times, consuming 23.2% of total runtime, with comparison operations taking another 33.4%.
- **Optimized approach**: Maintains a sorted `tails` array where `tails[k]` stores the smallest tail value of any increasing subsequence of length `k+1`. For each element, uses `bisect.bisect_left()` to find its insertion position in O(log n) time.

**Why this is faster:**
1. **Eliminates nested iteration**: Instead of comparing each element with all previous elements (1.6M comparisons in the profiler), we perform just one binary search per element (~5,800 searches for ~5,800 elements).
2. **Leverages optimized C implementation**: Python's `bisect` module is implemented in C and highly optimized for sorted list operations.
3. **Reduces memory operations**: No repeated array indexing in tight loops. The `tails` list grows incrementally and stays small (max length = LIS length, not input length).

**Performance characteristics from test results:**
- **Small arrays** (< 10 elements): Modest 20-150% speedup due to overhead being comparable to the O(n²) work.
- **Medium arrays** (~30-100 elements): 2,000-23,000% speedup as the quadratic penalty becomes significant.
- **Large arrays** (400-500 elements): **31,000-96,000% speedup** - the profiler shows original runtime of 3.66s vs optimized 16.7ms for the same workload.
- **Worst-case patterns**: Descending sequences show 31,707% speedup (was O(n²) comparisons with no updates, now O(n log n) searches).

**Impact considerations:**
The optimization maintains identical correctness (handles integers, floats, negatives, duplicates, edge cases) while dramatically improving performance on any input size > ~10 elements. Given the massive speedup on realistic data sizes, this change would benefit any workload calling this function repeatedly or on non-trivial arrays.
@codeflash-ai codeflash-ai bot requested a review from aseembits93 January 16, 2026 05:20
@codeflash-ai codeflash-ai bot added ⚡️ codeflash Optimization PR opened by Codeflash AI 🎯 Quality: High Optimization Quality according to Codeflash labels Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚡️ codeflash Optimization PR opened by Codeflash AI 🎯 Quality: High Optimization Quality according to Codeflash

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant