[output] | def mergeArrays(nums1, nums2): result = [] i = j = 0 while i < len(nums1) and j < len(nums2): if nums1[i] < nums2[j]: result.append(nums1[i]) i += 1 else: result.append(nums2[j]) j += 1 result += nums1[i:] + nums2[j:] §§ 1080 return result print(mergeArray [instruction] | Given two sorted arrays nums1 and nums2, combine their elements into a single array that is sorted. [input] | nums1 = [1, 2, 3] nums2 = [2, 4, 5]
[output] | static bool IsPalindrome(string s) { int n = s.Length; for (int i = 0; i < n / 2; i++) { if (s[i] != s[n-i-1]) return false; } return true; } Console.Write(IsPalindrome(s)); // true [instruction] | Create a function in C# which takes a string as an input and returns a boolean value indicating if the string is a palindrome or not. [input] | s = "racecar"
[output] | def isValidWord(s): words = open("words_alpha.txt").readlines() return s in words print(isValidWord(s)) // true [instruction] | Write a function to determine if a given string is a valid English word or not. [input] | s = "construct"
[output] | int sum(int a, int b) { return a + b; } std::cout << sum(a, b) << std::endl; // 30 [instruction] | Create a program in C++ which takes a pair of elements as input and returns their sum. [input] | a = 10 b = 20
[output] | public static void selectionSort(int[] arr) { for (int i = 0; i < arr.length - 1; i++) { int min_idx = i; for (int j = i + 1; j < arr.length; j++) { if (arr[j] < arr[min_idx]) min_idx = j; } int temp = arr[min_idx]; arr[min_idx] = arr[i]; arr[i] = temp; } } [instruction] | Implement selection sort algorithm to sort an array of integers in Java. [input] | arr = [5, 8, 2, 7, 1]
[output] | def mergeArrays2(nums1, nums2): i = j = 0 while i < len(nums1) and j < len(nums2): if nums1[i] > nums2[j]: nums1[i], nums2[j] = nums2[j], nums1[i] j += 1 else: i += 1 nums1.sort() nums2.sort() print(nums1) // [1, 2, 5] print(nums2) // [7, 8] [instruction] | Given two unsorted arrays, merge them in a sorted form without using any extra space. [input] | nums1 = [5, 8, 2] nums2 = [7, 1]
[output] | def kthLargestCharacter(s, k): char_dict = {} for c in s: if c not in char_dict: char_dict[c] = 1 else: char_dict[c] += 1 char_list = sorted(char_dict.items(), key=lambda x : x[1], reverse = True) return char_list[k - 1][0] print(kthLargestCharacter(s, k)) // l [instruction] | Given a string s and an integer k, find the kth largest character of s. [input] | s = "hello" k = 3
[output] | import random def generatePhoneNumber(): nums = [str(random.randint(0, 9) for _ in range(10))] return '-'.join([''.join(nums[:3]), ''.join(nums[3:6]), ''.join(nums[6:])]) print(generatePhoneNumber() // "567-444-0116" [instruction] | Generate a random phone number using random numbers in Python. [input] |
[output] | SELECT employee_id, first_name, last_name, age FROM Employees ORDER BY age DESC LIMIT 10; [instruction] | Write a MySQL query to select the 10 oldest employees from the Employees table. [input] | Employees table is defined as: (employee_id int, first_name varchar(255), last_name varchar(255), age int).
[output] | for i in range(len(arr)): for j in range(len(arr)-i-1): if arr[j] > arr[j+1] : arr[j], arr[j+1] = arr[j+1], arr[j] Resulting array = [1, 2, 3, 5, 8] [instruction] | Sort the following array of numbers in-place using the bubble sort algorithm: [5, 3, 2, 8, 1]. [input] |
[output] | CREATE TABLE employees ( id SERIAL PRIMARY KEY, name VARCHAR(50) not null, age INTEGER not null, address VARCHAR(50) ); [instruction] | Create a table in PostgreSQL using the following columns: id, name, age and address. [input] |
[output] | String str = "Good morning!"; [instruction] | Write a Java statement to declare a string variable, “str”, and initialize it with a value “Good morning!”. [input] |
[output] | The best way to store user input in JavaScript is to use the localStorage object. The localStorage object is part of the web storage API and provides a way to store data on the user's computer. The data is stored in key/value pairs and is accessible even after the browser is closed and reopened. The [instruction] | What is the best way to store user input in JavaScript? [input] |
[output] | SELECT first_name, last_name FROM Employees WHERE age > 25; [instruction] | Write a SQL query to print out the names of employees in the Employees table who are older than 25. [input] | Employees table is defined as: (employee_id int, first_name varchar(255), last_name varchar(255), age int).
[output] | import React from 'react'; const App = () => { return( <div className="container"> <h1>Welcome!</h1> <div> <h2>I'm a React App</h2> <p>This is an example code to render a DOM structure.</p> </div> </div> ); } export default App; [instruction] | Write a ReactJS code to render the following DOM structure. [input] | <div class="container"> <h1>Welcome!</h1> <div> <h2>I'm a React App</h2> <p>This is an example code to render a DOM structure.</p> </div> </div>
[output] | def first_vowel(string): index = 0 for char in string: if char in ["a", "e", "i", "o", "u"]: return index else: index+= 1 return -1 [instruction] | Create a function to search a given string for the first vowel. [input] |
[output] | int arr[10]; [instruction] | Write a C++ statement to create an array of 10 elements. [input] |
[output] | for element in my_list: print(element) [instruction] | Construct a Python loop to display the elements in the following list. [input] | my_list = [1, 2, 3, 4]
[output] | SELECT name, age FROM students WHERE age > 25; [instruction] | Write a SQL query to display the names and ages of students older than 25. [input] |
[output] | <html> <head> <title>Text Capturing</title> </head> <script> function captureText() { var text = document.getElementById("inputBox").value; alert("Entered text: " + text); } </script> <body> <h1> Text Capturing </h1> <input type="text" id="inputBox" /> [instruction] | Write an HTML program to capture the entered text in an input box [input] |
[output] | def odd_numbers_array(n): array = [] for i in range(0,n+1): if i%2 != 0: array.append(i) return array [instruction] | Create an array of all the odd numbers between 0 and n (inclusive). [input] |
[output] | public class LinkedList { private Node head; // head of the list // linked list Node. // This inner class is made static // so that main() can access it static class Node { int data; Node next; // Constructor Node(int d) { [instruction] | Implement a Java class for a LinkedList. [input] |
[output] | // C++ implementation of the linear search #include <iostream> using namespace std; // A iterative linear search function to search 'x' in arr[] // of size 'n' int search(int arr[], int n, int x) { int i; for (i = 0; i < n; i++) if (arr[i] == x) return i; [instruction] | Write an algorithm in C++ for linear search. [input] |
[output] | import java.util.Scanner; public class SumOfTwoNumbers { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int num1, num2, sum; System.out.print("Enter first number:"); num1 = scanner.nextInt(); System.out [instruction] | Generate a Java program to read two numbers from the user and print their sum. [input] |
[output] | function findMax(num1, num2) { return Math.max(num1, num2); } [instruction] | Suggest a method in JavaScript for finding the maximum of two numbers. [input] |
[output] | def fahrenheit_to_celsius(temp): return (temp - 32) * 5/9; # Driver code temperature = float(input("The temperature in Fahrenheit: ")) print("Temperature in Celsius: {}".format( fahrenheit_to_celsius(temperature))) [instruction] | Create a program in Python for converting Fahrenheit to Celsius. [input] |
[output] | public class StringEquality { public static void main(String[] args) { // two strings String s1, s2; s1 = "Hello"; s2 = "Hello"; if (s1.equals(s2)) System.out.println("Strings are equal."); else System.out.println("Strings are not equal."); } } [instruction] | Generate a program in Java that reads two strings and checks if the strings are equal. [input] |
[output] | SELECT * FROM books WHERE price > 10; [instruction] | Construct a SQL query to find all the books with a price over £10. [input] |
[output] | public class Program { public static int SearchElement(int[] arr, int value) { for (int i=0; i<arr.Length; i++) { if (arr[i] == value) return i; } return -1; } public static void Main() { int[] myArray = { 1, 2, [instruction] | Generate a C# code for searching an element in an array. [input] |
[output] | public static int maxSubArraySum(int a[]) { int size = a.length; int maxSoFar = Integer.MIN_VALUE, maxEndingHere = 0; for (int i = 0; i < size; i++) { maxEndingHere = maxEndingHere + a[i]; if (maxSoFar < maxEndingHere) maxSoFar = maxEndingHere; [instruction] | Create an algorithm in Java for maximum subarray problem. [input] |