[output] | [1, 0, 1, 0] [instruction] | To an integer array, apply a modulo operation. [input] | arr = [3, 4, 5, 6] m = 2
[output] | 30 [instruction] | Given two numbers, find their LCM. [input] | a = 15 b = 10
[output] | def rotate_arr(arr): return arr[-1:] + arr[:-1] [instruction] | Create a function that rotates a given array by one element to the right. [input] | arr = [1, 2, 3, 4, 5]
[output] | def check_overlap(rect1, rect2): x1, y1, w1, h1 = rect1 x2, y2, w2, h2 = rect2 x_overlap = max(0, min(x1 + w1, x2 + w2) - max(x1, x2)) y_overlap = max(0, min(y1 + h1, y2 + h2) - max(y1, y2)) overlap_area = x_overlap * y_overlap return (overlap_area > 0) [instruction] | Write a code to check if two rectangles overlap with each other. [input] | rect1 = (0,0,10,10) rect2 = (8,8,12,12)
[output] | def bubbleSort(arr): n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1] : arr[j], arr[j+1] = arr[j+1], arr[j] return arr arr = [3, 4, -5, 6, 1, -2] print(bubbleSort(arr)) [instruction] | Given the following list, write a program to sort it in ascending order. [input] | [3, 4, -5, 6, 1, -2]
[output] | print('Hello World') [instruction] | Create a program that prints "Hello World" on the screen. [input] |
[output] | def transpose(matrix): row_major = [] row, col = len(matrix), len(matrix[0]) for i in range(col): row_major.append([]) for j in range(row): row_major[i].append(matrix[j][i]) return row_major [instruction] | Write a function that transposes a 2D array from column-major format to row-major format. [input] | The array is [[1,2,3],[4,5,6],[7,8,9]]
[output] | # Get the latest version of Python latest_python=$(curl -s https://www.python.org/ftp/python/) # Get the filename from the link python_filename="${latest_python##*/}" # Download the version wget https://www.python.org/ftp/python/$python_filename # Unpack the file tar -xzf $python_filename # Install [instruction] | Write a shell script that download and install the latest version of Python 3. [input] |
[output] | <?php // Create connection object $conn = new mysqli('hostname', 'username', 'password', 'database_name'); // Set the query string $sql = "INSERT INTO users (username, email, password) VALUES (?, ?, ?)"; // Prepare a statement $stmt = $conn->prepare($sql); // Bind parameters to the query $stmt->b [instruction] | Create a PHP script to insert values into a table [input] | The table name is 'users' and the fields are username, email and password
[output] | import requests url = "https://example.com/api/getData" response = requests.get(url) data = response.json() [instruction] | Create an HTTP request to get the data from the given API and parse it into a JSON object. [input] | https://example.com/api/getData
[output] | query getData { users { id name email } } [instruction] | Create a GraphQL query to get the data from the given API. [input] | { users { id name email } }
[output] | transposed_matrix = [ [1, 4, 7], [2, 5, 8], [3, 6, 9] ] [instruction] | Take the following matrix and transpose it. [input] | matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
[output] | def divisible_by_five(numbers): new_list = [] for num in numbers: if num % 5 == 0: new_list.append(num) return new_list [instruction] | Create a function to filter out all numbers evenly divisible by 5. [input] | numbers = [10, 30, 45, 50, 16, 41]
[output] | def levelOrder(root): if root is None: return queue = [] queue.append(root) while(len(queue) > 0): print (queue[0].data), node = queue.pop(0) if node.left is not None: queue.append(node.left) if node.right is not None: [instruction] | Given a binary tree, write a function to print out the elements in level order. [input] |
[output] | squared_list = [x**0.5 for x in my_list] [instruction] | Create a list comprehension to convert each element to its square root. [input] | my_list = [1, 4, 9, 16, 25]
[output] | import re pattern = r"[a-z]{5}" re.findall(pattern, string) [instruction] | Write a RegEx expression to find substrings of length 5 that are lowercase. [input] |
[output] | def rotateArray(arr, index): n = len(arr) temp = [] for i in range(n): temp.append(arr[(i + index) % n]) for i in range(n): arr[i] = temp[i] return arr # Test arr = [1, 2, 3, 4, 5] index = 2 rotated = rotateArray(arr, index) # Output print(rota [instruction] | Design an algorithm to rotate a given array in clockwise direction by a given index. [input] | array = [1, 2, 3, 4, 5] index = 2
[output] | class DateInstance { constructor() { this.date = new Date(); } getDate() { return this.date; } setDate(dateValue) { this.date = dateValue; } } # Test dateInstance = new DateInstance(); print(dateInstance.getDate()); # Output: Thu [instruction] | Write a class in JavaScript that can be used to create an instance of a Date. [input] |
[output] | public class DecToBin { // function to convert from Decimal to binary public static String decToBin(int n) { String res = ""; while (n > 0) { res = (n % 2) + res; n = n / 2; } return res; } // Driver code [instruction] | Write a class in Java to convert a decimal number to its binary equivalent. [input] |
[output] | Palindrome: madam, DAD Not Palindrome: superman, abcdef [instruction] | Categorize each of the following strings as palindrome or not in Java. [input] | "madam", "DAD", "superman", "abcdef"
[output] | def print_welcome(n): for i in range(n): print("Welcome") [instruction] | Create an algorithm in Python to print the string “welcome” n times. [input] |
[output] | def pref_sum(a): output = [a[0]] for i in range(1, len(a)): output.append(a[i] + output[i-1]) return output [instruction] | Modify a given program to replace each element in an array with the sum of all elements before it. [input] | [1,2,3,4]
[output] | a * b; [instruction] | Select the correct answer from the following options to complete the Java code: int a = 12, b = 6; int result = ________ [input] |
[output] | def removeLetters(inputString, letter): outputString = "" for c in inputString: if c != letter: outputString = outputString + c return outputString print(removeLetters("This string contains multiple letter t's.", 't')) OUTPUT: "This string contains multiple letter s [instruction] | Create a function 'removeLetters' that takes a string and removes all instances of a given letter from it. [input] | String = "This string contains multiple letter t's." Letter = 't'
[output] | 12 [instruction] | Determine the output of the following function. def getSum(arr): total = 0 for i in arr: total += i return total arr = [2, 4, 6] [input] |
[output] | dlroW olleH [instruction] | What is the output of the following Python code? string = "Hello World" string = string[::-1] [input] |
[output] | def checkDigits(string): for char in string: if char not in '1234567890': return False return True print(checkDigits('12345')) OUTPUT: True [instruction] | Write a Python code to check if the given string contains only digits. [input] | string = "12345"
[output] | def combineStrings(string1, string2): return string1 + string2 print(combineStrings('Hello', 'World')) OUTPUT: HelloWorld [instruction] | Write a function 'combineStrings' which takes two strings and returns the combined string. [input] | string1 = "Hello" string2 = "World"
[output] | def checkInteger(number): if number == int(number): return True else: return False print(checkInteger(3.2)) OUTPUT: False [instruction] | Create a Python function 'checkInteger' that takes a number and returns true if the number is an integer, false otherwise. [input] | number = 3.2
[output] | def average(a, b, c): return (a + b + c) / 3 [instruction] | Define a function that takes three numbers and returns the average of them. [input] |