21. Write a program to merge two sorted arrays into a single sorted array.

Required Input:

Array 1: [1, 3, 5], Array 2: [2, 4, 6]

Expected Output:

Merged Array: 1, 2, 3, 4, 5, 6

Code In C#

using System; class MergeSortedArrays { static void Main() { // Merge the two sorted arrays into one } }

Run Code?

Click Run Button to view compiled output

22. Create a program to find the sum of diagonal elements in a hardcoded 2D square matrix.

Required Input:

Matrix:
[ [1, 2, 3],
 [4, 5, 6],
 [7, 8, 9] ]

Expected Output:

Diagonal Sum: 15

Code In C#

using System; class DiagonalSum { static void Main() { // Find the sum of diagonal elements in the matrix } }

Run Code?

Click Run Button to view compiled output

23. Write a program to rotate a hardcoded array to the right by a given number of steps.

Required Input:

Array: [1, 2, 3, 4, 5], Steps: 2

Expected Output:

Rotated Array: 4, 5, 1, 2, 3

Code In C#

using System; class RotateArray { static void Main() { // Rotate the array to the right by the given number of steps } }

Run Code?

Click Run Button to view compiled output

24. Create a program to check if two hardcoded strings are rotations of each other.

Required Input:

String 1: "abcd", String 2: "dabc"

Expected Output:

Are Rotations: True

Code In C#

using System; class StringRotationCheck { static void Main() { // Check if the two strings are rotations of each other } }

Run Code?

Click Run Button to view compiled output

25. Write a program to count the number of occurrences of each word in a hardcoded paragraph.

Required Input:

Paragraph: "C# is great and C# is fun"

Expected Output:

Occurrences:
C#: 2
is: 2
great: 1
and: 1
fun: 1

Code In C#

using System; using System.Collections.Generic; class WordFrequency { static void Main() { // Count the occurrences of each word in the paragraph } }

Run Code?

Click Run Button to view compiled output

26. Create a program to implement a simple LRU (Least Recently Used) Cache mechanism.

Required Input:

Cache Size: 3, Operations: [1, 2, 3, 4, 2, 5]

Expected Output:

Final Cache: 4, 2, 5

Code In C#

using System; using System.Collections.Generic; class LRUCache { static void Main() { // Implement the LRU Cache mechanism } }

Run Code?

Click Run Button to view compiled output

27. Write a program to calculate the sum of the border elements of a hardcoded 2D matrix.

Required Input:

Matrix:
[ [1, 2, 3],
 [4, 5, 6],
 [7, 8, 9] ]

Expected Output:

Border Sum: 40

Code In C#

using System; class BorderSum { static void Main() { // Calculate the sum of border elements in the matrix } }

Run Code?

Click Run Button to view compiled output

28. Create a program to find the longest consecutive sequence of numbers in a hardcoded array.

Required Input:

Array: [100, 4, 200, 1, 3, 2]

Expected Output:

Longest Sequence: 4

Code In C#

using System; using System.Collections.Generic; class LongestConsecutiveSequence { static void Main() { // Find the longest consecutive sequence in the array } }

Run Code?

Click Run Button to view compiled output

29. Write a program to determine if a hardcoded string contains only unique characters.

Required Input:

String: "abcdef"

Expected Output:

Contains Only Unique Characters: True

Code In C#

using System; class UniqueCharacters { static void Main() { // Check if the string contains only unique characters } }

Run Code?

Click Run Button to view compiled output

30. Create a program to reverse a hardcoded linked list using C#’s LinkedList<T> class.

Required Input:

Linked List: [1, 2, 3, 4, 5]

Expected Output:

Reversed List: 5, 4, 3, 2, 1

Code In C#

using System; using System.Collections.Generic; class ReverseLinkedList { static void Main() { // Reverse the linked list } }

Run Code?

Click Run Button to view compiled output

ad vertical

3 of 4