PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 13
Good morning! Here's your coding interview problem for today.

This problem was asked by Amazon.

Given an integer k and a string s, find the length of the longest substring that contains at most k distinct characters.

For example, given s = "abcba" and k = 2, the longest substring with k distinct characters is "bcb".



Pull request:
day 13 solution
Resolves #29 

Patch:
diff --git a/README.md b/README.md
index f6e2e37..c2c490e 100644
--- a/README.md
+++ b/README.md
@@ -23,3 +23,4 @@ problems from
 * [Day 11](https://github.com/vaskoz/dailycodingproblem-go/issues/23)
 * [Day 12](https://github.com/vaskoz/dailycodingproblem-go/issues/25)
 * [Day 12 Count and Deepest](https://github.com/vaskoz/dailycodingproblem-go/issues/27)
+* [Day 13](https://github.com/vaskoz/dailycodingproblem-go/issues/29)
diff --git a/day13/problem.go b/day13/problem.go
new file mode 100644
index 0000000..2b0c251
--- /dev/null
+++ b/day13/problem.go
@@ -0,0 +1,33 @@
+package day13
+
+// LongestSubKDistinct returns  find the length of the longest substring
+// that contains at most k distinct characters.
+// Runs in O(N) time. Uses O(K) space for the map.
+func LongestSubKDistinct(s string, k int) string {
+	r := []rune(s)
+	if len(r) <= k {
+		return string(r)
+	}
+	letters := make(map[rune]int)
+	var curL, maxL, curR, maxR int
+	for curR < len(r) {
+		if _, found := letters[r[curR]]; len(letters) < k || found {
+			letters[r[curR]]++
+			curR++
+			if curR-curL > maxR-maxL {
+				maxL, maxR = curL, curR
+			}
+		} else {
+			for len(letters) >= k {
+				if count := letters[r[curL]]; count == 1 {
+					delete(letters, r[curL])
+				} else {
+					letters[r[curL]]--
+				}
+				curL++
+			}
+		}
+
+	}
+	return string(r[maxL:maxR])
+}


Test patch:
diff --git a/day13/problem_test.go b/day13/problem_test.go
new file mode 100644
index 0000000..2a6dbfc
--- /dev/null
+++ b/day13/problem_test.go
@@ -0,0 +1,31 @@
+package day13
+
+import "testing"
+
+var testcases = []struct {
+	input    string
+	k        int
+	expected string
+}{
+	{"abcba", 2, "bcb"},
+	{"aa", 2, "aa"},
+	{"xyzabababbbbaaaac", 2, "abababbbbaaaa"},
+	{"xyzabababbbbaaaac", 2, "abababbbbaaaa"},
+}
+
+func TestLongestSubKDistinct(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := LongestSubKDistinct(tc.input, tc.k); result != tc.expected {
+			t.Errorf("Given %v I expected %v but got %v with k %v", tc.input, tc.expected, result, tc.k)
+		}
+	}
+}
+
+func BenchmarkLongestSubKDistinct(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			LongestSubKDistinct(tc.input, tc.k)
+		}
+	}
+}
Repository: sanctuary-js/sanctuary (js)

Issue:
toEither :: a -> b? -> Either a b
Suggested by @raine on [Gitter][1].

```javascript
> S.toEither('Invalid protocol', 'ftp://example.com/'.match(/^(http:|https:)[/][/]/))
Left("Invalid protocol")

> S.toEither('Invalid protocol', 'http://example.com/'.match(/^(http:|https:)[/][/]/))
Right(["http://", "http:"])
```

This would mirror [`S.toMaybe`][2].


[1]: https://gitter.im/plaid/sanctuary
[2]: https://github.com/plaid/sanctuary#toMaybe


Pull request:
Adds `toEither :: a -> b? -> Either a b`
A function for converting a possibly null-y value to an Either
Closes #83

Patch:
diff --git a/index.js b/index.js
index eb2c50a..275d724 100644
--- a/index.js
+++ b/index.js
@@ -1265,7 +1265,7 @@
 
   //# toMaybe :: a? -> Maybe a
   //.
-  //. Takes a value and returns Nothing if the value is null or undefined;
+  //. Takes a value and returns Nothing if the value is `null` or `undefined`;
   //. Just the value otherwise.
   //.
   //. ```javascript
@@ -1883,6 +1883,31 @@
       [b, $Either(a, b), b],
       function(x, either) { return either.isRight ? either.value : x; });
 
+  //# toEither :: a -> b? -> Either a b
+  //.
+  //. Converts an arbitrary value to an Either: a Left if the value is `null`
+  //. or `undefined`; a Right otherwise. The first argument specifies the
+  //. value of the Left in the "failure" case.
+  //.
+  //. ```javascript
+  //. > S.toEither('XYZ', null)
+  //. Left('XYZ')
+  //.
+  //. > S.toEither('XYZ', 'ABC')
+  //. Right('ABC')
+  //.
+  //. > R.map(R.head, S.toEither('Invalid protocol', 'ftp://example.com/'.match(/^https?:/)))
+  //. Left('Invalid protocol')
+  //.
+  //. > R.map(R.head, S.toEither('Invalid protocol', 'https://example.com/'.match(/^https?:/)))
+  //. Right('https:')
+  //. ```
+  S.toEither =
+  def('toEither',
+      {},
+      [a, b, $Either(a, b)],
+      function(x, y) { return y == null ? Left(x) : Right(y); });
+
   //# either :: (a -> c) -> (b -> c) -> Either a b -> c
   //.
   //. Takes two functions and an Either, and returns the result of


Test patch:
diff --git a/test/toEither.js b/test/toEither.js
new file mode 100644
index 0000000..407fb48
--- /dev/null
+++ b/test/toEither.js
@@ -0,0 +1,23 @@
+'use strict';
+
+var eq = require('./utils').eq;
+var S = require('..');
+
+
+describe('toEither', function() {
+
+  it('is a binary function', function() {
+    eq(typeof S.toEither, 'function');
+    eq(S.toEither.length, 2);
+  });
+
+  it('returns Left of the first argument when second argument is `null`-y', function() {
+    eq(S.toEither('a', null), S.Left('a'));
+    eq(S.toEither('a', undefined), S.Left('a'));
+  });
+
+  it('returns a Right of the second argument when it is not `null`-y', function() {
+    eq(S.toEither('a', 42), S.Right(42));
+  });
+
+});
Repository: ParkMyCar/compact_str (rust)

Issue:
impl PartialEq<CompactStr> for &str
Example that works:
```rust
use compact_str::CompactStr;
fn main() {
    dbg!(CompactStr::from("hello") == "hello");
}
```

Example that don't work:
```rust
use compact_str::CompactStr;
fn main() {
    dbg!("hello" == CompactStr::from("hello"));  
}
```

Error:
```
error[E0277]: can't compare `&str` with `CompactStr`
 --> src/main.rs:4:18
  |
4 |     dbg!("hello" == CompactStr::from("hello"));
  |                  ^^ no implementation for `&str == CompactStr`
  |
  = help: the trait `PartialEq<CompactStr>` is not implemented for `&str`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `test01` due to previous error
```

I think it shouldn't make any differences whether you want to compare `&str` with `CompactStr`, `&str` with `&CompactStr`, `CompactStr` with `&str` or `&CompactStr` with `&str`.

Pull request:
Add impl PartialEq<CompactStr> for &str
Fixes #14

Patch:
diff --git a/compact_str/src/lib.rs b/compact_str/src/lib.rs
index 52e7f527..ed5785f7 100644
--- a/compact_str/src/lib.rs
+++ b/compact_str/src/lib.rs
@@ -139,6 +139,12 @@ impl PartialEq<CompactStr> for String {
     }
 }
 
+impl PartialEq<CompactStr> for &str {
+    fn eq(&self, other: &CompactStr) -> bool {
+        *self == other.as_str()
+    }
+}
+
 impl Ord for CompactStr {
     fn cmp(&self, other: &Self) -> Ordering {
         self.as_str().cmp(other.as_str())


Test patch:
diff --git a/compact_str/src/tests.rs b/compact_str/src/tests.rs
index ec03277b..23031e6d 100644
--- a/compact_str/src/tests.rs
+++ b/compact_str/src/tests.rs
@@ -60,6 +60,7 @@ fn test_short_ascii() {
     for s in strs {
         let compact = CompactStr::new(s);
         assert_eq!(compact, s);
+        assert_eq!(s, compact);
         assert_eq!(compact.is_heap_allocated(), false);
     }
 }
@@ -79,6 +80,7 @@ fn test_short_unicode() {
     for (s, is_heap) in strs {
         let compact = CompactStr::new(s);
         assert_eq!(compact, s);
+        assert_eq!(s, compact);
         assert_eq!(compact.is_heap_allocated(), is_heap);
     }
 }
@@ -95,6 +97,7 @@ fn test_medium_ascii() {
     for s in strs {
         let compact = CompactStr::new(s);
         assert_eq!(compact, s);
+        assert_eq!(s, compact);
 
         #[cfg(target_pointer_width = "64")]
         let is_heap = false;
@@ -116,6 +119,7 @@ fn test_medium_unicode() {
     for (s, is_heap) in strs {
         let compact = CompactStr::new(s);
         assert_eq!(compact, s);
+        assert_eq!(s, compact);
 
         #[cfg(target_pointer_width = "64")]
         let is_heap = is_heap;