instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a recursive method to calculate the Fibonacci number of a given index, with the added constraint that the solution must have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Design a function which can check if a given year is a leap year and also determine if it falls on a Gregorian calendar. | codefeedback |
Create a class 'Stack' that has the following methods:
1. 'push': Adds an element to the top of the stack.
2. 'pop': Removes and returns the element at the top of the stack.
3. 'max_stack': Returns the maximum element in the stack.
The 'max_stack' method should have a time complexity of O(1).
Note: You can use any d... | codefeedback |
Construct a SQL query to find the list of customers with the highest total of sales, considering only sales made in the last month.
#Reasoning Steps#
1. Identify the sales table and the customers table in the database schema.
2. Join the sales and customers tables on the common column representing the customer ID.
3. ... | codefeedback |
Generate a list containing the squares of the first ten odd numbers, where the sum of the digits of each square is divisible by 3. | codefeedback |
Develop a PHP web application for a movie theater booking system.
Requirements:
1. Users should be able to register and login to the system.
2. Users should be able to view the list of movies currently playing in the theater.
3. Users should be able to select a movie and view its details, including the showtimes and a... | codefeedback |
Given a sentence, capitalize each word in the sentence using string functions. The sentence can contain multiple words separated by spaces.
To solve this problem, we can follow these steps:
1. Initialize an empty string to store the capitalized sentence.
2. Split the given sentence into a list of words using the spli... | codefeedback |
Given a JSON object containing an array of fruits, each with a type and count, find the total count of each type of fruit and display them in descending order based on the count.
{
"fruits": [
{ "type": "apple", "count": 10 },
{ "type": "orange", "count": 5 },
{ "type": "banana", "count": 1... | codefeedback |
Create a function called "find_primes" that takes two arguments, "start" and "end", and returns a list of all the prime numbers between the two.
The function should handle cases where the "start" value is greater than the "end" value and vice versa. In such cases, the function should still return a list of prime numb... | codefeedback |
Create a while loop that prints all the lowercase letters of the alphabet in reverse order. | codefeedback |
Given a matrix of integers, delete the row or column that contains the least number of prime numbers. | codefeedback |
Write a JavaScript code snippet to convert a string of uppercase characters to lowercase characters, while also removing any whitespace characters in the string.
input_string = "HELLO WORLD" | codefeedback |
Create a program that generates an XML file to store customer information, such as name, address, and contact details. The program should allow users to input multiple customer records and save them in the XML file. Additionally, the program should provide functionality to search for specific customers based on their n... | codefeedback |
Correct the following HTML code and check the output in a browser. The corrected code should include a responsive layout with a maximum width of 800 pixels and a minimum width of 300 pixels. Additionally, the paragraph text should be displayed in a different font style and color, with a font size of 18 pixels. | codefeedback |
Construct a regular expression that matches all strings that contain "hello" or "world" followed by an exclamation mark. | codefeedback |
Create a Flask endpoint for displaying a paginated list of items from a database, sorted in descending order of price.
Table name: 'items'
Columns: id (integer), name (string), price (float)
Requirements:
1. The endpoint should accept two query parameters: 'page' and 'limit'. 'page' should indicate the page number to ... | codefeedback |
Construct a C++ class with five data members and three functions. The class should have a constructor that initializes all the data members, a member function that calculates the sum of the data members, and a static member function that prints out the values of all the data members. Additionally, you should include a ... | codefeedback |
Use Python to generate a random string of length 8 using lowercase alphabetic characters. Additionally, the string should contain at least one uppercase alphabetic character and at least one numeric digit. | codefeedback |
Explain the difference between system call and library function. Also, provide an example of a system call and a library function in the C programming language. | codefeedback |
Explain the concept of hashing and how it relates to dictionaries in Python. | codefeedback |
Write a code snippet to implement bubble sorting in an array of 100 numbers. Additionally, handle the case where the array is already sorted in ascending order and return immediately without any unnecessary iterations. | codefeedback |
Write a code snippet for a function that deletes all occurrences of a specific element from an array. | codefeedback |
Given an XML string, parse the string and print the tag names and their corresponding values. Additionally, implement error handling to handle cases where the XML string is invalid or if a required tag is missing.
Example input:
<xml><title>HelloWorld!</title><body>This is my first XML document.</body></xml>
Expected... | codefeedback |
Given two strings, determine whether the first string is a substring of the second string.
Write a function named "is_substring" that takes in two string parameters, "string1" and "string2". The function should return a boolean value indicating whether "string1" is a substring of "string2" or not.
To solve this prob... | codefeedback |
Write a code to generate a random password with a given length. The password should contain at least one uppercase letter, one lowercase letter, one digit, and one special character. | codefeedback |
Explain how constructor chaining works in Java when there are multiple inheritance levels involved, and provide an example code snippet to demonstrate it. | codefeedback |
Using a for loop, print out the keys and values of a given dictionary in reverse order.
mydict = {
"name": "John",
"age": 30,
"city": "New York"
} | codefeedback |
Using a try-except statement, write a Python code to handle a ValueError which arises if the input is not a number. Additionally, implement a loop that allows the user to continue entering inputs until a valid number is provided. Finally, display a message to the user indicating the number of attempts it took to enter ... | codefeedback |
How would you use a while loop to sum up numbers from 0 to n, while also ensuring that the sum is only calculated for odd numbers? | codefeedback |
Write a code to split a list of numbers into two sets with equal sum. The sum of the numbers in the list will always be even. The list can contain duplicate numbers. The output should be the two sets of numbers that have equal sums. If it is not possible to split the list into two sets with equal sum, the code should r... | codefeedback |
Write code for a substring search with the following constraints and requirements:
- The substring should be case-insensitive.
- The substring should not be found if it is surrounded by other characters.
- The search should return the index of the first occurrence of the substring, or -1 if it is not found.
- The code ... | codefeedback |
Write a code to delete a node from a given BST, while also maintaining the property of a balanced BST. | codefeedback |
Create a program to find the maximum length common subsequence of two given strings.
String1: "abcdgf"
String2: "abcdhfe"
**Note:** A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. | codefeedback |
Write a code for creating a Fibonacci sequence with the following requirements:
- The user should input the value of 'n' where n is the number of terms in the Fibonacci sequence.
- The program should validate that the input is a positive integer greater than 1.
- The program should handle invalid inputs gracefully and ... | codefeedback |
Read the two given numbers and print the larger one. However, you are not allowed to use any comparison operators (such as > or <) in your solution. | codefeedback |
Write a function that takes two strings, "ABC" and "XYZ", as input and returns a list of all possible combinations of characters from both strings.
Constraints:
- The length of each input string will not exceed 10 characters.
- The output list should not contain any duplicate combinations.
- The characters in each com... | codefeedback |
Create a SQL query that returns the names, job titles, and salaries of all employees in the "Marketing" department, sorted by salary in descending order. Additionally, include the total number of employees in the "Marketing" department and the average salary of all employees in the company. | codefeedback |
Create an array of 10 integers, where each element is a prime number. | codefeedback |
Write a Java program to implement Matrix multiplication using only bitwise operators and without using any arithmetic operators. | codefeedback |
Write a program to calculate the area and circumference of a circle. The program should prompt the user to enter the radius of the circle, and then display the calculated area and circumference.
To calculate the area of a circle, you can use the formula: area = π * radius^2. To calculate the circumference of a circle,... | codefeedback |
Create a JavaScript function that can take a string and reverse it. The function should also handle string inputs containing special characters and numbers, while preserving the original case of each letter. The reversed string should not contain any leading or trailing whitespace characters. | codefeedback |
Write a Python script to identify all palindromes of length greater than or equal to 3 from a given input string. The script should return a list of all palindromes found.
inputString = "abacab"
Example:
Input: "abacab"
Output: ["aba", "aca"]
Note: The palindromes can overlap in the input string. | codefeedback |
Create an HTML page that uses Bootstrap to create a responsive navigation bar. Additionally, implement functionality that allows the navigation bar to collapse into a dropdown menu when viewed on smaller screen sizes. The dropdown menu should display the navigation links when clicked, and should close when a link is se... | codefeedback |
Write a JavaScript program to check if a given string contains equal number of P and T characters, and at least one U character. | codefeedback |
Input a two-dimensional array and calculate the sum of each row. However, some of the values in the array might be negative, so make sure to handle negative numbers correctly.
arr = [[1, -2, 3], [4, -5, 6], [-7, 8, -9]] | codefeedback |
Create a function that returns the sum of all elements in a given array of numbers. However, if any element in the array is a negative number, raise an exception with a custom error message. | codefeedback |
Write a Java program to count the number of characters in a sentence without using a loop. Additionally, you should not use any built-in Java methods for counting characters or manipulating strings. The sentence will only consist of lowercase and uppercase letters, spaces, and punctuation marks. The program should hand... | codefeedback |
Create a JavaScript program to convert the following date format into MM/DD/YYYY, ensuring that the program can handle different date formats and support multiple languages. The program should also validate the input date and handle any errors or invalid inputs gracefully. dateString = "October 5, 2020" | codefeedback |
Create a function that takes a 2D array of numerical values and returns the number of times the maximum value appears. The function should have a time complexity of O(n^2), where n is the length of the longest row in the 2D array. Additionally, the function should use only constant space complexity, i.e. it should not ... | codefeedback |
Create a prompt that takes user input, validates it, and displays a message based on the input. If the input is not valid, provide an error message and prompt the user again until valid input is provided. | codefeedback |
Create a Python class to store a customer's name, address, phone number, and email address. The email address should be validated to ensure it follows the standard format of "username@domain.com". | codefeedback |
Increase the difficulty by requiring the solution to extract the top 10 rows from a matrix with a size of n x m, where n and m are large integers (e.g. n > 1000, m > 1000). Additionally, the solution should only use core Python functionality and not rely on external libraries like NumPy. | codefeedback |
Write a SQL query to find the top three students with the highest GPA within a specific course, ordered by their GPA in descending order. | codefeedback |
Build a regression model to predict house prices based on crime rate, school quality, and the number of nearby amenities such as parks, restaurants, and shopping centers. Additionally, provide a piece of erroneous code that incorrectly calculates the mean squared error (MSE) instead of the root mean squared error (RMSE... | codefeedback |
Write a Python code to print a table format with 10 columns and 10 rows. Each cell in the table should contain a randomly generated number between 1 and 100.
Additionally, the code should calculate and print the sum of each row and each column. The sum of each row should be displayed at the end of each row, and the su... | codefeedback |
Use CSS to create a responsive grid layout with a light green background, black text, and a white border. The grid should have 4 columns and 3 rows. The first row should contain a header with a font size of 24px, the second row should contain a paragraph with a font size of 16px, and the third row should contain a butt... | codefeedback |
Find the last 15 digits of the result of raising 2 to the power of 1000. | codefeedback |
Create a Django model that includes a user's name, email address, age, and a list of their favorite books. Additionally, the model should include a field to store the date the user joined the platform.
The model should also have a method that calculates the user's current age based on their birth date, which is not di... | codefeedback |
Write a program to generate a Fibonacci sequence up to the n-th number using recursion. However, the program should handle large values of n (greater than 10^6) efficiently and without causing a stack overflow. | codefeedback |
Write a SQL query to select the employee name, start date, and salary of all employees who have joined after 2018 and have a salary greater than the average salary of all employees in the company. | codefeedback |
Suggest a way to complete the following Python program which takes two strings as input and prints out the longer string. The program should have a time complexity of O(1) and should not use any built-in functions or libraries that directly determine the length of the strings. You may use any other built-in functions o... | codefeedback |
Create a function that takes two string arguments, where each string represents a large number with up to 10^6 digits. The function should add the two numbers together and return the result as a string.
For example:
string1 = "12345678901234567890"
string2 = "98765432109876543210"
The function should return "111111111... | codefeedback |
Design a struct in C that can be used to store personal information, such as name, age, address, phone number, and email. The struct should also include a function that allows the user to calculate the person's BMI based on their height and weight. | codefeedback |
Create a shell script that prompts the user to enter a directory name, and then creates the directory in the home directory. Additionally, the script should check if the directory already exists and provide an error message if it does. | codefeedback |
Use NumPy to create a 3x3 array of random numbers from -1 to 1. | codefeedback |
Analyze the given text using opinion mining and sentiment analysis. Take into account any additional context or information provided. Identify and extract the sentiment expressed in the text. | codefeedback |
Given an array of integers, find the number of unique items in the array. A unique item is an item that appears only once in the array.
arr = [1, 2, 1, 4, 5]
Additional Constraints:
- The array may contain negative numbers.
- The array may be empty.
- The array may contain duplicate values.
- The array may be very la... | codefeedback |
Construct a code to determine if two strings are equal, with a twist - the strings can be of different lengths.
abc
abcd | codefeedback |
Write a Python code that prints out the first 5 elements of a tuple in reverse order. | codefeedback |
Create a program to find the longest substring with unique characters and return the length of the substring. If there are multiple substrings with the same longest length, return the first occurring substring.
You can assume that the input string only contains lowercase English alphabets (a-z).
#Example#
Input:
"abc... | codefeedback |
Write a SQL statement to retrieve the first three customers from a table, sorted by their total order amount in descending order. | codefeedback |
Implement an optimized version of insertion sort that can efficiently sort a large array of integers in ascending order. The input array can contain duplicate values and may have a length up to 10^6. The implementation should have a time complexity of O(n^2) and a space complexity of O(1). Additionally, the algorithm s... | codefeedback |
Construct a function to detect if a binary tree is balanced.
A binary tree is balanced if the heights of the two subtrees of any node never differ by more than 1.
## Input:
- The root of a binary tree.
## Output:
- Return True if the binary tree is balanced, False otherwise.
## Example:
```python
tree = TreeNode(3)... | codefeedback |
Create a JavaScript function to find the length of the longest common substring between two given strings. | codefeedback |
Write a SQL query to get the title, year, and genre of the oldest movie in a database that has a runtime of at least 120 minutes. | codefeedback |
Write a Python function that takes an array of strings as an argument and returns a boolean. The function should only return True if all the strings in the array contain at least one digit and one uppercase letter. Otherwise, the function should return False. | codefeedback |
Write a code to get the top 1000 trending topics on Twitter with their volume using the Twitter API. | codefeedback |
Develop an algorithm in Python to determine whether two strings are anagrams, but without using the built-in Python functions or libraries for string manipulation and sorting. | codefeedback |
Suggest a solution to store years in ISO 8601 format in Python, but also include the functionality to convert the ISO 8601 format to a different date format such as 'mm-dd-yyyy'. | codefeedback |
Create a program using PHP to display the length of the longest common substring in two given strings. Additionally, ensure that the program handles cases where there are multiple longest common substrings with different lengths, and output all of them. | codefeedback |
Build a MapReduce job with Hadoop to find the 99th percentile of a given data set. Additionally, implement a custom combiner to optimize the intermediate data transmission and reduce network traffic. | codefeedback |
Write a script which takes a list as an argument and shuffles it. The script should not use any built-in functions or libraries for shuffling. The shuffled list should have all even numbers before odd numbers. The original list should remain unchanged. The length of the list should not exceed 100 elements. | codefeedback |
Generate an HTML page that displays a table of data fetched from a remote API. The table should have the following columns: "Name", "Age", "City". The data should be sorted by name in ascending order. | codefeedback |
Write a script which receives two integers as parameters and returns their average as output. Additionally, ensure that the script handles the case where one or both of the parameters are not integers and raises an appropriate error message. | codefeedback |
Suggest a method in Python for sorting a list of strings on the basis of their length in descending order. | codefeedback |
Suggest an efficient algorithm for validating a password which should contain at least 1 uppercase character, 1 lowercase character, 1 digit, and 1 special character. Additionally, the password must be between 8 and 16 characters in length, and cannot contain any spaces. | codefeedback |
Write a class in Python to represent a division with two integers and the following operations: addition, subtraction, multiplication, division, exponentiation, and modulo. Additionally, implement a method to calculate the factorial of a number. | codefeedback |
Write a Python function called `is_prime` that takes an integer as input and returns a boolean value indicating whether the input is a prime number or not. Additionally, provide a piece of erroneous code that falsely claims to correctly detect prime numbers and explain why it is incorrect. | codefeedback |
Construct a for loop that prints out all prime numbers between 500 and 1000, and also counts the total number of prime numbers found. | codefeedback |
Write a program that detects the dominant language in a string. The program should consider additional languages, such as German, Italian, and Mandarin, in addition to French, Spanish, and English. The program should also handle cases where the string contains multiple paragraphs and special characters. | codefeedback |
Train a machine learning model to classify cats, dogs, and birds. Additionally, include a class for misclassified images. | codefeedback |
Compute the maximum value in a random array, but only consider the values that are divisible by 3.
[4,6,9,2,11,7] | codefeedback |
Compare 2 databases and update non matching information from database A to database B using SQL.
Table A:
| name | age |
|------|-----|
| John | 20 |
| Joe | 25 |
| Mary | 30 |
Table B:
| name | age |
|------|-----|
| John | 25 |
| Joe | 25 |
| Alex | 35 |
In this test, the tables have been extended to... | codefeedback |
Construct an SQL statement to select data from three tables, with a minimum of two joins. | codefeedback |
Construct an if-else statement that checks if the given day is a holiday. The day variable can be a string representing the day of the week (e.g., "Sunday", "Monday", etc.) or an integer representing the day of the month (e.g., 1 for January 1st, 2 for January 2nd, etc.). However, if the day variable is a string, it sh... | codefeedback |
Create a class in Java called Student with three fields called id, name, and grade. The grade field should be of type double. | codefeedback |
Create a program that finds the sum of all numbers divisible by 4 between 150 and 300, where the sum should only include numbers that are also divisible by 5. | codefeedback |
Identify the Python command to search a large text file for multiple specific keywords efficiently, while minimizing the time complexity. | codefeedback |
Write a PHP function called 'getUniqueValues' that takes an array called 'data' as input and returns an array containing only the unique values from the 'data' array. The function should have a time complexity of O(n) and a space complexity of O(n), where n is the number of elements in the 'data' array.
Example:
$data... | codefeedback |
Write a SQL statement to delete all records from a table called 'students' where the grade is below 3, but only if the student's enrollment date is before January 1st, 20 | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.