21. Implement a rate limiter using the token bucket algorithm.

Required Input:

Bucket Capacity: 5; Tokens Added per Second: 2; Requests: 5 at t=0, 2 at t=1, 1 at t=3

Expected Output:

t=0: 5 requests processed
t=1: 2 requests processed
t=3: 1 request processed
Remaining tokens: 3

Code In C#

using System; class TokenBucketRateLimiter { static void Main() { // Implement a token bucket rate limiter } }

Run Code?

Click Run Button to view compiled output

22. Find the longest palindromic substring in a hardcoded string.

Required Input:

String: "babad"

Expected Output:

Longest Palindromic Substring: bab

Code In C#

using System; class LongestPalindrome { static void Main() { // Find the longest palindromic substring } }

Run Code?

Click Run Button to view compiled output

23. Simulate a producer-consumer problem using multithreading.

Required Input:

Number of Producers: 1; Number of Consumers: 1; Buffer Size: 5

Expected Output:

Producer added item 1
Consumer removed item 1
Producer added item 2
Consumer removed item 2
Producer added item 3
Consumer removed item 3
Producer added item 4
Producer added item 5
Consumer removed item 4
Producer added item 6
Consumer removed item 5
Producer added item 7
Consumer removed item 6
Producer added item 8
Producer added item 9
Consumer removed item 7
Producer added item 10
Consumer removed item 8

Code In C#

using System; using System.Collections.Generic; using System.Threading; class ProducerConsumer { static void Main() { // Simulate producer-consumer using threads } }

Run Code?

Click Run Button to view compiled output

24. Implement a Least Frequently Used (LFU) cache.

Required Input:

Capacity: 3; Operations: Put(1, "A"), Put(2, "B"), Put(3, "C"), Get(1), Put(4, "D")

Expected Output:

Get(1): A
Cache:
1: A
4: D
3: C

Code In C#

using System; using System.Collections.Generic; class LFUCache { static void Main() { // Implement a Least Frequently Used (LFU) cache } }

Run Code?

Click Run Button to view compiled output

25. Perform operations on a sparse matrix representation.

Required Input:

Matrix: [[0, 0, 3], [0, 5, 0], [6, 0, 0]]

Expected Output:

Original Matrix:
0 0 3 
0 5 0 
6 0 0 
Sparse Matrix: (0, 2, 3), (1, 1, 5), (2, 0, 6)
Reconstructed Matrix:
0 0 3 
0 5 0 
6 0 0 

Code In C#

using System; using System.Collections.Generic; class SparseMatrix { static void Main() { // Perform operations on a sparse matrix } }

Run Code?

Click Run Button to view compiled output

26. Perform image convolution for a simple kernel on a grayscale image matrix.

Required Input:

Matrix: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; Kernel: [[0, -1, 0], [-1, 4, -1], [0, -1, 0]]

Expected Output:

Convolved Matrix:
0 0 4 
3 0 7 
16 11 22 

Code In C#

using System; class ImageConvolution { static void Main() { // Perform convolution of the matrix using the kernel } }

Run Code?

Click Run Button to view compiled output

27. Implement the KMP (Knuth-Morris-Pratt) algorithm for substring matching.

Required Input:

Text: "abcabcabdabc"; Pattern: "abcabd"

Expected Output:

Pattern found at index 3

Code In C#

using System; class KMPSubstringSearch { static void Main() { // Implement the KMP algorithm for substring matching } }

Run Code?

Click Run Button to view compiled output

ad vertical

3 of 3