[output] | The maximum sum of a subarray of length 3 is 51 (20 + 5 +26). [instruction] | Calculate the maximum sum of a subarray of length k. [input] | Array: [1, 3, 4, 5, 20, 32] K: 3
[output] | def cube_sum(n): sum = 0 for i in range(1,n+1): sum += i**3 return sum [instruction] | Calculate the sum of the cube of integers from 1 to n. [input] |
[output] | def find_path(array, source, dest): path = [source] sx, sy = source while path[-1] != dest: dx, dy = path[-1] if dx > 0 and array[dx - 1][dy] == 0: path.append([dx-1, dy]) elif dy > 0 and array[dx][dy-1] == 0: path.append([dx, dy-1]) [instruction] | Write a function to find the path from a source point to a destination point in a given 2D array. [input] | Array: [[0, 1, 0, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 1, 0], [0, 0, 0, 1, 0]] Source Point: [0, 0] Destination Point: [3, 4]
[output] | The sum of the products of the digits of 1234 with its reverse is 30. sum = (1*4) + (2*3) + (3*2) + (4*1) = 30. [instruction] | Find the sum of the products of the digits of a given number with its reverse. [input] | Number = 1234
[output] | class Queue: def __init__(self): self.queue = [] def enqueue(self, val): self.queue.append(val) def dequeue(self): if self.queue: return self.queue.pop(0) else: return None def peek(self): if self.queue: r [instruction] | Implement a queue following the classic FIFO (First-in-first-out) principle using Python. [input] |
[output] | public class LongestString { public static String getLongestString(String[] array) { if(array.length == 0) { return null; } String longestString = array[0]; for(int i = 1; i < array.length; i++) { if(array[i].len [instruction] | Given an array of strings and the task is to find the longest string from the given string array. [input] | ["Google", "Facebook", "Amazon", "Zapier" ]
[output] | <table> <tr> <th>Header 1</th> <th>Header 2</th> <th>Header 3</th> </tr> <tr> <td>Row 1 Column 1</td> <td>Row 1 Column 2</td> <td>Row 1 Column 3</td> </tr> <tr> <td>Row 2 Column 1</td> <td>Row 2 Column 2</td> <td>Row 2 Column 3</td> </tr> <tr> <td>Row 3 Column 1</td> <td [instruction] | Generate HTML to create a table with 3 columns and 6 rows with the first row as the header. [input] |
[output] | import string import random def generate_password(): letter_lower = string.ascii_lowercase letter_upper = string.ascii_uppercase symbols = string.punctuation digits = string.digits password = ''.join(random.choice(letter_lower + letter_upper + symbols + digits) for i in range(8)) return pa [instruction] | Write a Python function to generate a random password with length 8 containing any combination of upper and lowercase letters, numbers, and symbols. [input] |
[output] | SELECT genre, COUNT(*) as total_movies FROM Movies GROUP BY genre [instruction] | Create a SQL query to count the total number of movies for every genre in the database. [input] |
[output] | #!/bin/bash for file in {first,second,third}.txt; do touch $file for i in {1..10}; do echo "This is line $i in the file $file" >> $file done done [instruction] | Create a bash script that creates three TextFiles named first.txt, second.txt, and third.txt each having 10 lines of text. [input] |
[output] | data = ["James", "John", "Susan", "Bella", "Natalie", "Adam", "Sam", "Eric"] filtered_data = [name for name in data if len(name) > 5] print(filtered_data) # Output: ["James", "John", "Bella", "Natalie", "Sam"] [instruction] | Write a code to filter out the names longer than 5 characters from the following list. [input] | data = ["James", "John", "Susan", "Bella", "Natalie", "Adam", "Sam", "Eric"]
[output] | import datetime def get_difference_in_seconds(timestamp1, timestamp2): datetime1 = datetime.datetime.strptime(timestamp1, "%Y-%m-%d %H:%M:%S") datetime2 = datetime.datetime.strptime(timestamp2, "%Y-%m-%d %H:%M:%S") difference = (datetime2 - datetime1).total_seconds() return differen [instruction] | Create a code to get the difference between two timestamps in seconds. [input] | timestamp1 = "2020-07-02 14:13:37" timestamp2 = "2020-07-03 13:21:46"
[output] | def scale(arr, n): return [x * 2 for x in arr[:n]] [instruction] | Suggest a way to scale the following function for n values. [input] | def scale(x): return x * 2
[output] | def second_largest(arr): largest = max(arr) arr.remove(largest) return max(arr) [instruction] | Given an array of integers, create a code to return the second-largest number. [input] | [12, 45, 2, 41, 31, 10, 8, 6, 4]
[output] | def gen_binary_strings(n): result = [] for i in range(2**n): s = bin(i)[2:] s = s.zfill(n) result.append(s) return result print(gen_binary_strings(5)) # Output: ['00000', '00001', '00010', '00011', '00100', '00101', '00110', '00111', '01000', '01001', '01010', '0 [instruction] | Write a code to generate all possible binary strings of length 5. [input] |
[output] | def create_userid(firstname, lastname): userid = firstname[0] + lastname[:5] return userid userid = create_userid("John", "Smith") print(userid) # Output: JSmith [instruction] | Create a code to create a userid from the given firstname and lastname. [input] | Firstname: John Lastname: Smith
[output] | def max_product_three_numbers(arr): arr.sort() return max(arr[-1] * arr[-2] * arr[-3], arr[0] * arr[1] * arr[-1]) max_product = max_product_three_numbers([-1, -2, 4, 5, 8, 9]) print(max_product) # Output: 360 [instruction] | Given a list of numbers, create a code to find the maximum product of three numbers. [input] | [-1, -2, 4, 5, 8, 9]
[output] | public class Animal { // instance variables private String name; private int age; // constructor public Animal(String name, int age) { this.name = name; this.age = age; } // methods public void eat() { System.out.println("I'm e [instruction] | Generate a code snippet to define a class called Animal in Java. [input] |
[output] | <button id="button">Click me!</button> <script> document.getElementById('button').addEventListener('click', function(){ this.innerText="I am clicked!"; }); </script> [instruction] | Create an HTML view with a button that changes its text when clicked. [input] |
[output] | CREATE DATABASE customers_and_products; USE customers_and_products; CREATE TABLE customers ( id INT NOT NULL AUTO_INCREMENT, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, PRIMARY KEY(id) ); CREATE TABLE products ( id [instruction] | Create a database to store customer data and products. [input] |
[output] | SELECT * FROM Students WHERE City = 'London'; [instruction] | Write a SQL query to find students residing in a particular city. [input] | City: London
[output] | int merge(int arr[], int temp[], int left, int mid, int right) { int i, j, k; int inv_count = 0; i = left; /* i is index for left subarray */ j = mid; /* j is index for right subarray */ k = left; /* k is index for resultant merged subarray */ while ((i <= mid - 1) && [instruction] | Create a C++ function to determine the number of inversions in an array. [input] |
[output] | def KMPSearch(pat, txt): M = len(pat) N = len(txt) # create lps[] that will hold the longest prefix suffix # values for pattern lps = [0]*M j = 0 # index for pat[] # Preprocess the pattern (calculate lps[] array) computeLPSArray(pat, M, lps) i = [instruction] | Create a KMP algorithm in Python to find a pattern in a given text. [input] | Text: abcabdababd Pattern:abd
[output] | my $str = 'John, Paul, George and Ringo'; my @names = split(',\s', $str); foreach my $name (@names) { print $name; } [instruction] | Create a Perl script to parse a given string and extract all names. [input] |
[output] | def generateRange(start:Int, end:Int): List[Int] = { if (start > end) List(end) else start :: generateRange(start+1, end) } [instruction] | Write a Scala function to generate a range of numbers. [input] |
[output] | function printFibonacciSeries(n) { let a = 0, b = 1; // Iterate through the series and print the // value for every number for (let i = 1; i <= n; i++) { console.log(a); let sum = a + b; a = b; b = sum; } } // Driver code let n = 10; printFibonacciSeries(n); [instruction] | Create a JavaScript program to generate Fibonacci series up to a given number. [input] |
[output] | SELECT COUNT(*) FROM Employees WHERE Department='HR' AND Gender='F'; [instruction] | Construct an SQL query to find the total number of female employees with a certain department in a company. [input] | Department: HR
[output] | # Validate if the inputs are valid dates def validate_dates(date_list): if len(date_list) == 0: return True prev_date = date_list[0] for date in date_list[1:]: if date < prev_date: return False prev_date = date return True [instruction] | Given the following code, write a function to validate the input dates are in increasing order. [input] | # Validate if the inputs are valid dates def validate_dates(date_list): pass
[output] | def remove_nulls(dictionary): if isinstance(dictionary, dict): return {key: remove_nulls(value) for key, value in dictionary.items() if not value == None} else: return dictionary [instruction] | Write a function in Python to remove all 'null' values from a nested dictionary. [input] |
[output] | class Student: def __init__(self, name): self.name = name def print_name_upper(self): print(self.name.upper()) [instruction] | Add a method to the following class which prints the student's name in upper case. [input] | class Student: def __init__(self, name): self.name = name