[output] | // Algorithm to find the longest palindromic substring int longestPalindromicSubstr(char* str) { // Variables to store the start and the end of the palindromic substring int maxLen = 1; int start = 0; int len = strlen(str); // Table to store boolean value at the index // dp[i][j] stores whet [instruction] | Write an algorithm that finds the longest palindromic substring of a given input string. [input] | "forgeeksskeegfor"
[output] | function flattenArray(arr, depth) { let result = []; for (let item of arr) { if (Array.isArray(item) && depth > 0) { result.push(...flattenArray(item, depth - 1)); // Recursively flatten the array } else { result.push(item); } } return result; } [instruction] | Write a JavaScript function to flatten an array up to the given depth. [input] | [1, [2, [3, [4, 5], 6], 7], 8], 3
[output] | class ToggleButton extends React.Component { constructor(props) { super(props); this.state = { buttonState: false, }; } handleClick() { this.setState({ buttonState: !this.state.buttonState }); } render() { let buttonText = this.state.buttonState ? 'ON' : 'OF [instruction] | Write a React component that implements a toggle button. [input] | <div> <ToggleButton /> </div>
[output] | // Algorithm to find the least common ancestor in a binary tree Node *LCA(Node *root, Node *p, Node *q) { /* Base case */ if (root == NULL) return NULL; // If either p or q matches with root's key, report // the presence by returning root (Note that if a key is // ancestor of other, the [instruction] | Write an algorithm that finds the least common ancestor of two given nodes in a binary tree. [input] | 1 / \ 2 3 / \ / \ 4 5 6 7 Least Common Ancestor (LCA) of 4 and 5
[output] | #my-id { // Your CSS here } [instruction] | Write a CSS selector that selects the element with the id "my-id". [input] | <div id="my-id">Hello</div>
[output] | class Person: def __init__(self, name, age): self.name = name self.age = age [instruction] | Create a constructor for the following class in Python. [input] | class Person: def __init__(self, name, age): self.name = name self.age = age
[output] | let result = jsonObject.name; // result will be 'John' [instruction] | Write a code snippet to query the following json object using JavaScript. [input] | const jsonObject = { "name": "John", "age": 30, "city": "New York" }
[output] | function printPattern() { for (let i = 1; i <= 5; i++) { let str = ''; for (let j = 1; j <= 5; j++) { if (j <= i) { str += j; } } console.log(str); } } [instruction] | Create a JavaScript function to print the following pattern. [input] |
[output] | def multiply_dicts(d1, d2): for key in d1: if key in d2: d1[key] = d2[key] [instruction] | Identify the bugs in the following python code and fix them. [input] | def multiply_dicts(d1, d2): for key in d1: d1[key] = d2[d1[key]]
[output] | counter = 0 while counter < 10: print("Current counter is: " + str(counter)) counter += 1 [instruction] | Provide a solution for a ``while`` loop that runs for 10 iterations and prints out its current counter at each iteration. [input] |
[output] | import time for i in range(10): print(i) time.sleep(1) [instruction] | How would you modify the following code to add a time delay of 1 second between each iteration of the loop? [input] | for i in range(10): print(i)
[output] | def add_two_strings(string1, string2): """A function to add two strings together and return the concatenated result.""" if isinstance(string1, str) and isinstance(string2, str): return string1 + string2 else: raise TypeError("Both arguments must be strings") [instruction] | In the following code, identify the bug and suggest a fix. [input] | def add_two_strings(string1, string2): return string1 + string2
[output] | class MathCalculations: """ Class to perform math calculations """ def __init__(self): pass def add(self, num1, num2): """ Add two numbers """ return num1 + num2 def subtract(self, num1, num2): """ Subtract two numbe [instruction] | Create a class in Python for performing basic math calculations [input] |
[output] | #Iterate over a list list = [1, 2, 3, 4, 5] for item in list: print(item) [instruction] | How to create a loop in Python which will iterate over a list? [input] |
[output] | // Create a class Node class Node { constructor(value) { this.value = value; this.next = null; this.prev = null; } } // Create a class LinkedList class DoublyLinkedList { constructor() { this.head = null; this.tail = null; this.length = 0; } } [instruction] | Create a JavaScript code to represent a double-linked list [input] |
[output] | def compare_lists(l1, l2): if len(l1) != len(l2): return False for i in range(len(l1)): if l1[i] != l2[i]: return False return True [instruction] | How to compare two lists in Python? [input] |
[output] | function sortByLength(arr) { arr.sort(function(a,b){ return a.length - b.length; }); return arr; } [instruction] | How to sort an array of strings by length in JavaScript? [input] |
[output] | CREATE TABLE users ( user_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 (user_id) ); [instruction] | Create a MySQL table to store users with the following columns: user_id (int), first_name (varchar), last_name (varchar), and email (varchar). [input] |
[output] | def triangle_area(side): return side * (side ** 0.5) / 2 [instruction] | Design a function in Python to calculate the area of an equilateral triangle. [input] |
[output] | SELECT * FROM users WHERE email = 'john@example.com'; [instruction] | Create a MySQL query to select all users from the 'users' table with the given email address. [input] | 'john@example.com'
[output] | class Student { private: int age; string name; public: Student(int a, string n) : age(a), name(n) {} int getAge() { return age; } string getName() { return name; } void setAge(int a) { age = a; } void setName(string n) { name = n; } }; [instruction] | Create a C++ class named 'Student' with private member data including age and name. [input] |
[output] | int arr[] = {4, 78, 32, 6}; [instruction] | Create an array with elements {4, 78, 32, 6}. [input] |
[output] | To make an HTTP request using cURL, you need to install and set up cURL, select the correct HTTP method, provide a URL, and set any necessary options. You can then execute the cURL request by calling curl_exec() and get the response via curl_getinfo() and curl_exec(). [instruction] | What do you need to do in order to make an HTTP request using cURL? [input] |
[output] | public static void swap(int x, int y){ int temp = x; x = y; y = temp; } [instruction] | Write a Java method to swap of two integer values. [input] |
[output] | String s1 = "Hello"; String s2 = "World"; [instruction] | Break the following string into two pieces. [input] | "HelloWorld"
[output] | Python supports for loops, while loops, and nested loops. Additionally, the loop statement can be used to construct an infinite loop. [instruction] | Which type of loops can be used in Python? [input] |
[output] | function removeLastChar(str){ return str.substring(0,str.length-1); } [instruction] | Write a JavaScript function to remove the last character of a string. [input] |
[output] | fruits = ["apple", "banana", "orange"] fruits.push("mango"); [instruction] | Edit the following code to add an item to the 'fruits' list. [input] | fruits = ["apple", "banana", "orange"]
[output] | <?php function calculateAverage($marks) { $sum = 0; for($i = 0; $i < count($marks); $i++) { $sum += $marks[$i]; } $average = $sum / count($marks); return $average; } ?> [instruction] | Write a PHP function to calculate the students' average marks. [input] | $marks = [40, 70, 60, 90];
[output] | <!DOCTYPE html> <html> <head> <title>Country and Capital Table</title> </head> <body> <h1>Country and Capital Table</h1> <table> <tr> <th>Country</th> <th>Capital</th> </tr> <tr> <td>India</td> <td>New Delhi</td> </tr> <tr> <td>United States</td> <td>Washington DC</ [instruction] | Create an HTML page that has a table and populates the table with the given data. [input] | Country | Capital India | New Delhi United States | Washington DC Canada | Ottawa