[output] | public static boolean compareStrings(String str1, String str2) { int str1Length = str1.length(); int str2Length = str2.length(); if (str1Length != str2Length) return false; for (int i=0; i<str1Length; i++){ if (str1.charAt(i) != str2.charAt(i)) retur [instruction] | Generate a Java program for comparing two strings for equality. [input] |
[output] | def swap(arr, i, j): temp = arr[i] arr[i] = arr[j] arr[j] = temp [instruction] | Given an array, write a function that swaps the elements at indices i and j. [input] | arr = [3, 5, 7, 4, 9, 2]
[output] | console.log("Hello!"); [instruction] | Write a JavaScript program that logs a message to the console. [input] | "Hello!"
[output] | function maxValue(x, y, z) { return Math.max(x, y, z); } [instruction] | Create a function that takes in three parameters, x, y, and z, and returns the maximum value. [input] | x = 8, y = 4, z = 12
[output] | sentence = "My favorite color is red" words = sentence.split() [instruction] | Split a given sentence into a list of words. [input] | "My favorite color is red"
[output] | <table> <tr><th>Name</th><th>Age</th><th>City</th></tr> <tr><td>John</td><td>20</td><td>London</td></tr> <tr><td>Bob</td><td>19</td><td>Paris</td></tr> <tr><td>Alice</td><td>18</td><td>New York</td></tr> </table> [instruction] | Build an HTML table based on the given data. [input] | cols = [{"name": "Name", "type": "string"}, {"name": "Age", "type": "number"}, {"name": "City", "type": "string"}] rows = [["John", 20, "London"], ["Bob", 19, "Paris"], ["Alice", 18, "New York"]]
[output] | string = "Hello, World!" count = 0 for char in string: if char == 'o': count += 1 print(count) [instruction] | Count the number of times the letter "o" appears in this string. [input] | "Hello, World!"
[output] | model = keras.models.Sequential() # Add an input layer model.add(keras.layers.InputLayer(input_shape=input_shape)) # Add one or more dense layers model.add(keras.layers.Dense(64, activation='relu')) # Add an output layer for prediction model.add(keras.layers.Dense(num_classes, activation='softmax [instruction] | Create a new Keras model with the given input shape and output layer. [input] | input_shape=(10, 20, 3) num_classes=2
[output] | def product_array(arr): res = [] product = 1 for i in range(len(arr)): product *= arr[i] for i in range(len(arr)): res.append(int(product/arr[i])) return res [instruction] | Write a function that takes an array of integers and returns an array of the same size with each element equal to the product of all the elements in the original array except itself. [input] | [1, 2, 3]
[output] | def generate_outcomes(): outcomes = [] for p1 in ['rock', 'paper', 'scissors']: for p2 in ['rock', 'paper', 'scissors']: outcomes.append((p1, p2)) return outcomes [instruction] | Rock-paper-scissors is a classic two player game. Create a program to generate all the possible outcomes of individual rounds in Rock Paper Scissors. [input] |
[output] | def show_temperature(temp): fahrenheit = (temp * 9/5) + 32 return '{} degrees Celsius corresponds to {} degrees Fahrenheit'.format(temp, round(fahrenheit, 1)) [instruction] | Write a function to display a temperature in Celsius with the corresponding temperature in Fahrenheit. [input] |
[output] | def filter_5_length(arr): res = [] for string in arr: if len(string) == 5: res.append(string) return res [instruction] | Create a function to check an array of strings and return a list of strings that have length of 5. [input] | ["Ironman", "Spiderman", "Hulk", "Captain America", "Thor"]
[output] | def contains_vowel(string): vowels = ['a', 'e', 'i', 'o', 'u'] for char in string.lower(): if char in vowels: return True return False [instruction] | Write a function to check if a string contains either 'a' or 'e' or 'i' or 'o' or 'u'. [input] |
[output] | <html> <head> <title>John Doe's information</title> </head> <body> <h1>John Doe</h1> <p> Address: 123 Main Street <br> Email: john@example.com <br> Phone: 987654321 </p> </body> </html> [instruction] | Create an HTML page that displays the name, address, email and phone number of a given user. [input] | Name: John Doe Address: 123 Main Street Email: john@example.com Phone: 987654321
[output] | function isPalindrome(word){ return word == word.split("").reverse().join(""); } [instruction] | Write a JavaScript function that returns 'true' if a given string is a palindrome, and 'false' otherwise. [input] |
[output] | public class LinkedList { Node head; static class Node { int data; Node next; Node(int d) { data = d; next = null; } } public void deleteNode(int position) { if (head == null) { return; } [instruction] | Write code to delete an element of a linked list given its position. [input] | Linked List: 8->3->65->7 Position: 2
[output] | Quick sort is the fastest amongst quicksort, mergesort, and heapsort. It is an efficient, widely-used sorting algorithm. Quicksort is typically faster than mergesort and heapsort for sorting an unsorted array of size 1000. The worst-case performance of quicksort is O(n^2) and the average-case perfor [instruction] | Compare the performance of quicksort, mergesort and heapsort on an unsorted array of size 1000. [input] |
[output] | <html> <head> <title>Countries and Capitols</title> </head> <body style="background-color: #f9f9f9; font-family: sans-serif; padding: 50px"> <h1 style="text-align:center; color: #444444;">World Countries and Capitols</h1> <p>Below is a list of countries and capitols, presented in three c [instruction] | Create a web page to display a result of a dictionary containing all countries in the world and its corresponding capital in three columns. [input] |
[output] | RunTotal <- function(numbers) { runningTotal <- 0 totals <- c() for (i in 1:length(numbers)) { runningTotal <- runningTotal + numbers[i] totals <- c(totals, runningTotal) } return(totals) } [instruction] | Code an R function to compute the running total of a given array of numbers. [input] | [1, 4, 8, 5, 2, 9]
[output] | from django.db import models class User(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) email = models.EmailField(unique=True) birth_date = models.DateField() is_active = models.BooleanField(default=True) created_at = m [instruction] | Create a Django model class to represent a User. [input] |
[output] | class MyStack { int top; int capacity; int stack[]; // Creating stack MyStack(int capacity) { this.capacity = capacity; stack = new int[capacity]; top = -1; } // Adding an element on top of the stack public void push(int [instruction] | Design a stack using a dynamic array in Java. [input] |
[output] | function findFirstVowel(str) { var vowels = ["a", "e", "i", "o", "u"]; for(var i = 0; i < str.length; i++) { if(vowels.indexOf(str[i].toLowerCase()) !== -1) return i; } return -1; } [instruction] | Write code to identify the first vowel in a string in JavaScript. [input] |
[output] | def findKthSmallestElement(arr, n, k): # To return kth smallest element in # the given array return arr[k-1] [instruction] | Given a sorted array of size n, create a program to return the kth smallest element. [input] |
[output] | import os directory = os.getcwd() print("The current working directory is", directory) files = os.listdir(directory) print("The files in the current directory are", files) for file in files: if file.endswith(".py"): print("The Python script", file, "is in the current directory") [instruction] | Show an example of using the Python module, os. [input] |
[output] | class Node: def __init__(self, data): self.left = None self.right = None self.data = data def maxDepth(node): if node is None: return 0 else: leftDepth = maxDepth(node.left) rightDepth = maxDepth(node.right) if leftDepth > rightDe [instruction] | Suggest a completion for the following Python code to find the depth of a given binary tree. [input] | class Node: def __init__(self, data): self.left = None self.right = None self.data = data def maxDepth(node):
[output] | def powerset(s): result = [[]] for x in s: result.extend([y + [x] for y in result]) return result [instruction] | Make the following Python function for generating powerset. [input] |
[output] | def merge_arrays(arr1, arr2): arr3 = arr1 + arr2 # Combine the arrays arr3.sort() # Sort the combined array return arr3 # Return the newly sorted array [instruction] | Define a function to merge two sorted arrays into a single sorted array. [input] | arr1 = [1, 3, 5, 7] arr2 = [2, 4, 8, 10]
[output] | <?php $arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; // Create an empty array to store even numbers $even_numbers = []; // Loop through the array, check if each element is even // If even, add to the even numbers array foreach($arr as $item) { if($item % 2 == 0) { array_push($even_numbers, $item [instruction] | Write a script to identify the even numbers in the given PHP array. [input] | $arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
[output] | def odd_numbers(arr): oddArr = [] # Empty array to be populated for item in arr: if item % 2 != 0: # Check if number is odd oddArr.append(item) # Add to array return oddArr # Return the array [instruction] | Write a script to create a new array with only the odd numbers from the given array. [input] | [3, 4, 6, 8, 9, 10]
[output] | def search(nums, x): for i, n in enumerate(nums): if n == x: return i return -1 [instruction] | Write a Python algorithm to search a list of numbers for the index of the given element. [input] | nums = [5,7,11,23,44,30] x = 11