prompt: Write a Python function to reverse a string.

code:
def reverse_string(s):
    return s[::-1]

explanation: This function uses slicing.


prompt: Check if a number is prime.

code:
function isPrime(n) {
  for (let i = 2; i < n; i++) {
    if (n % i === 0) return false;
  }
  return n > 1;
}

explanation: This loops from 2 to n-1 to test divisibility.


prompt: Binary search algorithm.

code:
int binarySearch(int[] arr, int target) {
  int l=0,r=arr.length-1;
  while(l<=r){ int m=(l+r)/2; if(arr[m]==target)return m; else if(arr[m]<target)l=m+1; else r=m-1; }
  return -1;
}

explanation: This implements standard binary search logic in Java.