[output] | def get_list_size(head): count = 0 temp = head while(temp): count += 1 temp = temp.next return count [instruction] | Find a way to get the size of a linked list without traversing it. [input] | head: 1 -> 2 -> 3 -> 4 -> 5 -> null
[output] | def smallest_subarray_sum(arr, sum): start = 0 end = 1 min_length = float('inf') current_sum = arr[start] while(end < len(arr)): while(current_sum < sum and end < len(arr)): current_sum += arr[end] end += 1 while(start < end and current_s [instruction] | Write a function to find the smallest subarray with a given sum. [input] | arr = [3, 4, 5, 6, 7], sum = 11
[output] | def power_of_2(n): result = 1 for i in range(n): print(result) result *= 2 [instruction] | Edit the following code so that it prints out all powers of 2 up to 2^n [input] | n = 5
[output] | def reverse_string_without_parity(str): # Create empty string reversed_str = "" # Iterate through the input string in the reverse order for i in range(len(str)-1,-1,-1): reversed_str += str[i] return reversed_str [instruction] | Create a function that reverses a given string without using the built-in parity. [input] | str = 'I am here for the coding challenge"
[output] | def power(base, exponent): result = 1 for _ in range(exponent): result *= base return result [instruction] | Find a way to calculate the power of a number without using * or ** [input] | base = 3 exponent = 4
[output] | The possible output types for the given task are Double, Int, Float, and Long. [instruction] | Identify the possible output types for the following task. [input] | Task: Write a Spark program to calculate the mean and the median of a set of numbers.
[output] | SELECT id, prof_name FROM teachers WHERE rank = 'Associate Professor' // fixed the rank. [instruction] | Rewrite this SQL query in Postgres. [input] | SELECT id, prof_name FROM teachers WHERE rank = 'assistant'
[output] | public class Student { private String id; private String name; private int age; public Student(String id, String name, int age) { this.id = id; this.name = name; this.age = age; } public String getId() { return id; } public v [instruction] | Create a Java class for representing a student object. [input] |
[output] | The error in the HTML page is that there is no closing <body> tag. The HTML page should have a closing </body> tag after the <h2>Welcome!</h2> tag. [instruction] | Find the errors in this HTML page. [input] | <html> <title> My Webpage </title> <body> <h2>Welcome!</h2> </head> </html>
[output] | Object-oriented programming (OOP) is a programming paradigm that is based on the concept of objects which contain both data and methods. These objects can interact with each other to create complex systems. Procedural programming is a programming paradigm that is based on the concept of procedures o [instruction] | Explain the differences between OOP and procedural programming. [input] |
[output] | arr = [] for i in range(10): arr.append(i) sum = 0 for num in arr: sum += num [instruction] | Rewrite this code into Python. [input] | ArrayList<Integer> arr = new ArrayList<>(); for (int i = 0; i < 10; i++) { arr.add(i); } int sum = 0; for(int num : arr){ sum += num; }
[output] | Create a package containing API authentication logic and all the necessary API keys. Set up a cloud service, such as AWS or GCP, and deploy the package. Configure the cloud service to accept incoming requests and authenticate the user using the API keys. [instruction] | Build a package and deploy it in the cloud. [input] | The package is an API to authenticate users and the API should be able to authenticate users having different types of API keys.
[output] | SELECT count(*) FROM customer c JOIN sales s on c.cust_id = s.cust_id GROUP BY c.cust_id HAVING SUM(s.quantity) > 5; [instruction] | Write a SQL query to find the number of customers that have purchased a product more than 5 times. [input] | The database has three tables: customer(cust_id, cust_name, balance) product(prod_id, prod_name, price) sales(cust_id, prod_id, quantity)
[output] | #include <iostream> int main() { int a, b; cin >> a >> b; if (a == b) { cout << a; } return 0; } [instruction] | Fix the following C++ code segment. [input] | #include <iostream> int main() { if (a == b) { cout << a;
[output] | def is_anagram(str1, str2): # convert the strings to lowercase str1 = str1.lower() str2 = str2.lower() # sorting both the strings s1 = sorted(str1) s2 = sorted(str2) if len(s1) != len(s2): return False # compare character by character for i in [instruction] | Create a function that takes in two strings and determines of the strings are anagrams [input] | String 1: "spite" String 2: "pists"
[output] | Type error: The function sum_of_values() takes a list as an argument, but the argument provided is an integer (5). [instruction] | Identify any type error that is present in the following code. [input] | def sum_of_values(num_list): total = 0 for value in num_list: total += value return total/len(num_list) square_value = sum_of_values(5)
[output] | <html> <head> <title>Bar Chart Representing Total Sales</title> <script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script> <style> canvas{ -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; } </style> </head> <body> <div [instruction] | Write a HTML page to display a bar chart representing the total sales of a company in different months. [input] | Months: Jan, Feb, Mar, Apr, May Total sales in each month: 2500, 4000, 4500, 6000, 5500
[output] | def compute_average(lst): total = 0 for num in lst: total += num # calculate the average avg = total / len(lst) return avg # Driver Code lst = [1, 2, 3, 4, 5] print("Average of the list =", round(compute_average(lst), 2)) [instruction] | Given a list of integers, write a function to compute their average. [input] | List of integers: [1, 2, 3, 4, 5]
[output] | The purpose of a classifier model in machine learning is to predict the class or category of an input data point. A classifier acts as a decision boundary between different categories of data points. It takes a set of input features, applies a set of mathematical operations to them, and uses them to [instruction] | Explain what is the purpose of a classifier model in machine learning [input] |
[output] | def generate_combinations(string): result = [] for i in range(len(string)): for j in range(i + 1, len(string) + 1): result.append(string[i:j]) return result if __name__ == '__main__': string = "abcd" print(generate_combinations(string)) # outputs ['a', 'ab', [instruction] | Generate all combinations of the string "abcd". [input] |
[output] | def split_string(string, character): return string.split(character) if __name__ == '__main__': string = "A/B/C/D" character = "/" print(split_string(string, character)) # outputs ['A', 'B', 'C', 'D'] [instruction] | Create a program to split the given string on a specific character. [input] | String: "A/B/C/D" Character: "/"
[output] | app.get('/users', (req, res) => { const users = [ { id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Jack' }, ]; const userNames = users.map(user => user.name); res.status(200).json(userNames); }); [instruction] | Create a REST API endpoint that returns a list of all user names from a list of users. [input] |
[output] | * { font-style: italic; } [instruction] | Write a CSS style to turn all text in a document to italic. [input] |
[output] | class Student: def __init__(self, name, age, major): self.name = name self.age = age self.major = major def get_name(self): return self.name def get_age(self): return self.age def get_major(self): return self.major [instruction] | Create a Python class to hold a student's information: name, age and major. [input] |
[output] | No output is produced when compiling the above code in C++. Any warnings or errors should be indicated while compiling. [instruction] | Compile the following code in C++ and check for any warnings or errors. [input] | #include<iostream> using namespace std; int main() { cout << "Hello World!"; return 0; }
[output] | const temperatures = { 2015: 34.7, 2016: 35.2, 2017: 35.7, 2018: 36.1, 2019: 36.7 }; [instruction] | Create a JavaScript object that holds the global temperatures for the last 5 years. [input] |
[output] | binomial_coeff <- function(n, k) { if((k == 0) | (k == n)) return(1) else return(binomial_coeff(n-1, k-1) + binomial_coeff(n-1,k)) } [instruction] | Write an R function to calculate the binomial coefficient of n and k [input] |
[output] | public class MultiplicationTable { public static void main(String[] args) { for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { System.out.print(i * j + " "); } System.out.println(); } } } [instruction] | Create a Java program to print out the multiplication table for the first 10 numbers [input] |
[output] | public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tvTimeDate = findViewById(R.id.tvTimeDate); SimpleDateFormat dateFormat = new SimpleDateFor [instruction] | Write an Android app to display the current time and date [input] |
[output] | send, Steve. [instruction] | Extract words starting with 's' in this sentence. [input] | Sentence: I send a package to Steve.