[output] | public static int binarySearch(int[] array, int x) { int low = 0, high = array.length - 1; while (low <= high) { int mid = (low + high) / 2; if (array[mid] < x) low = mid + 1; else if (array[mid] > x) [instruction] | Write a method to implement binary search using Java. [input] |
[output] | SELECT * FROM Employees; [instruction] | Construct an SQL query for fetching all rows from a table named "Employees". [input] |
[output] | ^[a-z0-9_]*$ [instruction] | Create a regular expression for validating a lowercase alphabet, number, or underscore. [input] |
[output] | for (int i=0; i<10; i++) { // execute block of code } [instruction] | Construct a for loop for iterating 10 times and executing a block of code. [input] |
[output] | <h1 style="display: block; text-align: center; font-size: 2em; color: #FF0000;">My Webpage</h1> [instruction] | Style the following title with css. [input] | <h1>My Webpage</h1>
[output] | def f(n): i = 0 while i < n: i+=1 # Fixed missing indentation if i % 5 == 0: print(i) # Added missing closing bracket after print() statement [instruction] | Debug the following function. [input] | def f(n): i = 0 while i < n: i+=1 if i % 5 == 0: print(i)
[output] | class Book: def __init__(self, title, author, year): self.title = title self.author = author self.year = year def get_title(self): return self.title def get_author(self): return self.author def get_year(self): return [instruction] | Construct an object-oriented code for a Book class. [input] |
[output] | The algorithm should use pre-processing techniques like image cropping, normalization, and thresholding to convert the raw input image into a binary image. It should then use feature extraction techniques like contours, corner detection, and Hough Transform to detect and separate the characters from [instruction] | Create an algorithm that can recognize handwriting. [input] |
[output] | A better algorithm for calculating Fibonacci sequence is the iterative method. Instead of making recursive calls, this method computes each element of the Fibonacci sequence in a loop. This method is more efficient and requires less memory overhead. The algorithm is as follows: def iterative_fibona [instruction] | Suggest a better algorithm for calculating Fibonacci sequence. [input] |
[output] | def traverse_tree(root): if root is None: return traverse_tree(root.left) print(root.data) traverse_tree(root.right) [instruction] | Write a generic code for traversing a tree. [input] |
[output] | RegEx: [a-zA-Z] [instruction] | Write a regular expression that matches all English alphabets. [input] |
[output] | class MainViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } } [instruction] | Create a new view controller class named "MainViewController". [input] |
[output] | const array = [1,2,3,4]; for (let i = 0; i < array.length; i++) { console.log(array[i]); } [instruction] | Write a JavaScript program to iterate through a 1D array, and print each value. [input] | array = [1,2,3,4]
[output] | An SQL JOIN is a clause that allows for combining data from multiple tables in a relational database. A JOIN combines records from two or more tables based on the values from one or more columns. It is used in SELECT statement to join the results of two or more tables and then display the result set [instruction] | What is an SQL JOIN? [input] |
[output] | class MainView: UIView { override func draw(_ rect: CGRect) { // code to customize the main view } } [instruction] | Create a new View subclass of UIView and name it "MainView". [input] |
[output] | HTML5 Canvas is an HTML element that can be used to draw graphics and animation with JavaScript scripts. It provides the ability to render graphics on the fly without the need for any plugins. Canvas elements are rendered as bitmap images which can be manipulated with code to create dynamic effects. [instruction] | What is HTML5 Canvas? [input] |
[output] | enum MobilePhoneBrand { case Apple case Samsung case Huawei case Oppo case Vivo case Xiaomi } [instruction] | Create a Swift enum to represent the different mobile phone brands. [input] |
[output] | .main { margin: 0 auto; width: 100%; display: block; text-align: center; } [instruction] | Write a CSS rule to center a container with class "main". [input] |
[output] | SELECT * FROM users; [instruction] | Construct an SQL statement to retrieve data from a table called "users". [input] |
[output] | The type of layout used in this HTML structure is a Grid Layout. The columns are divided into equal widths, which creates a grid pattern. The content within each column is arranged horizontally. [instruction] | Identify the type of layout used in this HTML structure. [input] | <div class="container"> <div class="row"> <div class="column"><h1>Title</h1></div> </div> <div class="row"> <div class="column"><p>Content</p></div> <div class="column"><p>Content</p></div> <div class="column"><p>Content</p></div> </div> </div>
[output] | <?php //Initialize cURL $curl = curl_init(); //Set cURL parameters curl_setopt_array($curl, array( CURLOPT_URL => "http://path.to/api/", CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array("Content-type: application/json") )); //Execute cURL $respons [instruction] | Write a PHP script to fetch data from an API. [input] |
[output] | Recursion is a method of problem solving where the solution to a problem relies on solving smaller instances of the same problem. In computing, recursion is a process by which a method calls itself continuously. A base case is used to terminate the recursion, and each time the method calls itself, i [instruction] | How does recursion work? [input] |
[output] | class Car { private string make; private string model; private int year; public Car(string make, string model, int year) { this.make = make; this.model = model; this.year = year; } public string getMake() { return this.make; } public [instruction] | Create a C# class named "Car" that models a car. [input] |
[output] | A.sort(reverse=True); [instruction] | Suggest a way of sorting an array of integers A in descending order. [input] | A = [4, 7, 2, 9, 6];
[output] | <div class="circle" style="border-radius: 100px; background-color: black; height: 100px; width: 100px;"></div> [instruction] | Edit the following HTML code so that it displays a black, 100px border-radius circle. [input] | <div class="circle"></div>
[output] | try: if (len(list) == 0): print("List is empty") except: print("No list is given") [instruction] | Rewrite the following code using try and except blocks. [input] | if (len(list) == 0): print("List is empty")
[output] | 10 [instruction] | Run the following program and provide the console output. [input] | def multiply(x, y): return x * y print(multiply(2, 5))
[output] | print(", ".join(str(x) for x in list)) # Output: 3, 5, 7, 9, 11 [instruction] | Suggest a way to display the following list in a readable format. [input] | list = [3,5,7,9,11]
[output] | print(''.join([x if x not in 'aeiou' else '*' for x in string])) # Output: H*ll* W*rld! [instruction] | Suggest a way of replacing all the vowels in a string with a star (*). [input] | string = "Hello World!"
[output] | def caesar_encrypt(plaintext, k): ciphertext = "" # traverse text for i in range(len(plaintext)): char = plaintext[i] # Encrypt uppercase characters if (char.isupper()): ciphertext += chr((ord(char) + k-65) % 26 + 65) # Encrypt [instruction] | Suggest a way of encrypting text using a Caesar cipher. [input] | plaintext = "Hello World"