instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Implement a function in Python that takes in a list of integers and returns the sum of all the elements. You are not allowed to use the built-in `sum()` function or any other functions that directly compute the sum. Instead, you must use the `reduce()` function from the `functools` module to accomplish this task. Addit... | codefeedback |
Write a function in Python that takes a list of integers as input and returns a new list containing only the positive integers from the input list. The function should have a time complexity of O(n), should not use any built-in functions or libraries, and should also ensure that the resulting list is sorted in ascendin... | codefeedback |
Create a PHP script that implements a calculator class capable of performing basic arithmetic operations such as addition, subtraction, multiplication, and division. The calculator class should also handle complex numbers and support additional mathematical operations such as exponentiation and square root.
The script... | codefeedback |
Develop a solution for the Towers of Hanoi problem, with the additional constraint that each disk can only be moved to a tower that is at least three positions away from its current tower. Additionally, the solution must be implemented using a recursive algorithm without using any loops or iteration. | codefeedback |
Write a JavaScript code to sort a list of strings in alphabetical order in O(n^2) time complexity. The list may contain duplicate strings and may have a maximum length of 1000.
Reference code:
```
function bubbleSort(arr) {
var len = arr.length;
for (var i = 0; i < len; i++) {
for (var j = 0; j < len - i - 1; ... | codefeedback |
Write an R code to return the first 100 rows of a data frame, but only include rows where the sum of the values in the "population" column and the values in the "area" column is greater than 10 million. The data frame is stored in the file "states-data.csv". | codefeedback |
Write a regular expression that extracts all numbers from the given text, but excludes any numbers that are part of a phone number format.
Text: "The total number of students is 50 and the average score is 78 out of 100. Contact us at 555-123-4567 for any questions."
Additional Requirements:
- The regular expression s... | codefeedback |
Design an efficient algorithm that computes the Fibonacci numbers up to a given maximum value, taking into consideration the constraint that the algorithm should have a time complexity of O(n) and space complexity of O(1), where n is the maximum value.
In addition, the algorithm should handle large maximum values (up ... | codefeedback |
Generate a Python class definition for a pig object that includes the following properties and methods.
Properties:
1. name: string (must be a palindrome)
2. color: string (must be a valid HTML color code)
3. age: integer (must be a prime number)
Methods:
1. introduce(): prints out a statement introducing the pig by i... | codefeedback |
Using the HTML code provided, add a meta tag to the "head" element with the attribute "viewport" set to "width=device-width, initial-scale=1.0". | codefeedback |
Using the code provided, create an algorithm in Python to print only the prime numbers from 1 to 100, but without using any built-in functions or libraries for prime number generation or checking. You can only use basic arithmetic operations, loops, and conditional statements. | codefeedback |
Write a Python program to sort a list of tuples using Lambda. Each tuple contains two integers. The program should sort the list based on the sum of the integers in each tuple, in descending order. Additionally, the program should ignore any tuples where the sum of the integers is less than or equal to 5 and greater th... | codefeedback |
Using the code provided, modify the program to output "I like cats" instead of "I love cats". The program must now include at least one function named "convert_sentence" that takes a string as input and returns the converted sentence. The program must also handle cases with different capitalization and punctuation, and... | codefeedback |
Create a function that takes a string and converts the string to CamelCase. The function should only convert the string to CamelCase if the string contains at least one uppercase letter and at least one digit. Otherwise, it should return the original string. For example, if the input string is "this_is_a_string_123", t... | codefeedback |
Design and implement a pseudo-random number generator algorithm in Python that generates a sequence of numbers based on a given seed value. Discuss the limitations and potential biases that can arise from this algorithm and propose possible solutions to mitigate them.
Your implementation should include the following f... | codefeedback |
Write an SQL query for finding the minimum and maximum values of a column. Additionally, include the count of distinct values in that column, the average value of the column, and the sum of all values in the column. | codefeedback |
Create a database table to store real estate records, with the following requirements:
1. The table should have columns to store the following information for each property:
- Property ID (unique identifier)
- Property Name
- Property Type (e.g., house, apartment, land)
- Property Address
- Property Pr... | codefeedback |
Create a JavaScript function for getting the unique elements in an array without using any built-in array methods or additional data structures. The function should have a time complexity of O(n log n) and a space complexity of O(1).
const arr = [3, 1, 4, 3, 2, 5] | codefeedback |
Create a cURL request for getting the response from an API endpoint that requires authentication using a custom token in the request headers. Additionally, include error handling to gracefully handle any authentication errors and retry the request with a new token if necessary. | codefeedback |
Select all customers from the customer_table with age greater than 30, zip codes within a given range, and a last name that contains the letter 'e', while also filtering out customers whose names start with the letter 'A'.
customer_table = [['Eliza', 22, 48001], ['John', 26, 48034], ['Michael', 50, 48323], ['Alice', ... | codefeedback |
Construct a SQL query to select all records from a table called “customers” that have a value in the column “age” greater than 30 and less than 40, and adjust the order based on the column “last_name” in ascending order. Additionally, filter the results to only include records where the first name starts with the lette... | codefeedback |
You are given a sorted array of integers and you need to construct a balanced AVL tree from the array. Write a function that takes the array as input and returns the root of the AVL tree.
Note: You cannot use any built-in functions or libraries for AVL tree implementation. | codefeedback |
Create a PHP script to print the Fibonacci sequence up to the nth term, where n is provided as input to the script. Additionally, the script should implement error handling to handle invalid input values for n, such as negative numbers or non-integer values. | codefeedback |
Please create a class for a shopping cart in Python that can handle multiple users. Each user should have their own separate shopping cart instance. The shopping cart should be able to add items, remove items, calculate the total price of all items in the cart, and apply discounts if applicable.
Additionally, the shop... | codefeedback |
Write a PHP function for counting the number of words in a string, excluding any words that contain numbers or special characters. The function should also return the average length of the words in the string. Additionally, the function should ignore any words that are common English stopwords. The string should be cas... | codefeedback |
Write a code snippet in Python to generate a random float with up to 10 decimal places, without using any built-in functions or libraries for generating random numbers. | codefeedback |
Explain why a stack can be used to reverse a string in-place, without using any additional data structures, and provide a code snippet in a programming language of your choice that demonstrates how a stack can be implemented to reverse a string efficiently, while also maintaining constant space complexity. | codefeedback |
Implement a function that finds all possible combinations of a given string and returns them as a list of strings. The order of the combinations does not matter.
## Example ##
Input: "abc"
Output: ["", "a", "b", "c", "ab", "ac", "bc", "abc"]
Explain how your solution works step by step. Also, discuss the advantages a... | codefeedback |
Determine whether a given string is a palindrome using a stack data structure. The string may contain both lowercase and uppercase letters, and should be case-insensitive. Additionally, the string may also contain special characters and whitespace.
#Updated Test#
You are given a string containing alphanumeric characte... | codefeedback |
Create a function using JavaScript to generate a random string of exactly 20 characters in length, where each character is a randomly selected uppercase letter, lowercase letter, digit, or special character.
The function should have a time complexity of O(n), where n is the length of the string, and a space complexity... | codefeedback |
Complete the code to slice the list up to index 4 and reverse the order of the sliced portion. Output the reversed slice. However, you are not allowed to use any built-in functions or methods that directly manipulate the list. Additionally, your solution should have a time complexity of O(n), where n is the length of t... | codefeedback |
What is the final value of variable "a" at the end of the code, considering that "a" must remain positive throughout the execution of the loop? | codefeedback |
Construct a loop in JavaScript that prints out each item in an array in reverse order. The loop should also check if each item is a number and only print out the numbers. Additionally, the loop should only print out the numbers if they are greater than 2. Finally, the loop should stop iterating once it encounters a neg... | codefeedback |
Sort the following array of objects based on the 'name' key in descending order. If two objects have the same name, sort them based on the 'age' key in ascending order. Additionally, if two objects have the same name and age, sort them based on the 'id' key in ascending order.
arr = [
{ name: 'Bill', age: 25, id: 1... | codefeedback |
Write a SQL query to select all books with a title starting with "The" and ending with a number from the database. The number should be the same as the last digit of the book's year. The query should return the book's id, title, year, and the number of pages in the book.
Table: books
Columns: id, title, year, pages
En... | codefeedback |
Create a SQL query to count all buyers from a country, where the country name starts with the letter 'A' and the customer's name contains the word 'Tech'. Additionally, exclude any customers whose last name starts with the letter 'S'. | codefeedback |
Create a mongoose model for employees who have the fields 'name', 'age', 'gender', 'salary', 'employeeID', and 'department'. The 'employeeID' field should be a unique identifier for each employee and should be automatically generated when a new employee is created. Additionally, the 'name' field should only accept alph... | codefeedback |
Use a Linked List structure to implement a stack data structure. Your implementation should also support the following additional operations:
1. getSize() - returns the number of elements in the stack.
2. isEmpty() - returns true if the stack is empty, false otherwise.
3. peek() - returns the element at the top of the... | codefeedback |
Combine the two objects with the same property value, ensuring that the "name" property is case-sensitive and that the resulting object only contains properties that are present in both objects. | codefeedback |
Write a program that prompts the user to enter a list of positive integers and converts each number from decimal notation to binary notation. The program should then display the binary representation of each number.
In addition, the program should calculate and display the sum of all the binary numbers generated. | codefeedback |
Write an algorithm in pseudocode to convert a temperature given in Celsius to its equivalent value in Fahrenheit, while also handling the conversion of negative temperatures and rounding the result to two decimal places.
However, you must also implement a validation check to ensure that the user enters a valid tempera... | codefeedback |
Write a C++ program to determine the greatest common factor of two numbers, where each number can have up to 10^6 digits. The program should have a time complexity of O(log(min(a,b))), where a and b are the input numbers. Additionally, the program should not use any standard library functions or algorithms for calculat... | codefeedback |
Re-write the code below in Java to reverse the first string while preserving the order of the elements in the other strings. Additionally, the program should ignore any strings that contain duplicate characters and only reverse the first string if it has at least 3 characters. The program should also handle empty strin... | codefeedback |
Create a script that prints the prime numbers up to a given integer n. Additionally, implement a function that checks whether a given number is a prime number. The script should use a multi-threaded approach to optimize the prime number calculation. The function should not use any built-in prime number checking functio... | codefeedback |
Construct a regex expression to identify all prime numbers within a given string of digits, where each prime number must contain at least 3 digits and be greater than 100. | codefeedback |
Implement a function in Python that takes two array-like structures and returns a new array containing all elements from the first one that do not appear in the second one. The arrays may contain any type of element, including nested arrays. The function should also handle cases where the second array is a nested array... | codefeedback |
Design a procedure in SQL to get the average salary of employees for each department from the 'employees' table, while also calculating the median salary for each department. Additionally, include a column that displays the number of employees in each department who have a salary higher than the average salary for that... | codefeedback |
Design an SQL query to find all the records where the salary is between 10000 and 20000, and the age is less than 30, in the 'employees' table. Additionally, include a subquery that calculates the average salary for each department and returns only the records where the employee's salary is above the department's avera... | codefeedback |
Design a logic in Rust to check if an entered integer is a prime number or not. Additionally, you should also print all the prime numbers up to the entered integer. Your solution should not use any built-in prime number functions or libraries. The time complexity of your solution should be O(sqrt(n)) where n is the ent... | codefeedback |
Create a function in JavaScript to concatenate two strings without using the concat() method. The function should also ignore any whitespace at the beginning or end of the strings and handle cases where either of the strings is empty or contains only whitespace.
Additionally, ensure that the function is case-sensitive... | codefeedback |
Write a SQL query to select all rows where the age is greater than or equal to 30, the name starts with the letter 'A', and the employee is from the city 'New York'. Table name: employees. Table information: id, name, age, city. | codefeedback |
Write a piece of code in C++ to print all prime numbers between 1 and N, where N is a positive integer provided by the user. The code should also determine the sum of all prime numbers found and print it. Additionally, the code should also print the largest prime number found within the range. | codefeedback |
Write an algorithm in Python to count how many distinct words a given string contains. The algorithm should have a time complexity of O(n), where n is the length of the string. Additionally, the algorithm should not use any built-in Python functions or libraries for string manipulation or counting. | codefeedback |
Create a function in Java that takes an integer n (1 <= n <= 1000) as input and prints the first n Fibonacci numbers in reverse order. Additionally, the function should calculate the sum of all Fibonacci numbers that are multiples of 3 and not multiples of 2 within the first n numbers and return it. The function should... | codefeedback |
Create a function in JavaScript that removes all vowels from a string. Additionally, if the string contains any numbers, convert those numbers to their corresponding Roman numeral representation before removing the vowels. The function should have a time complexity of O(n), where n is the length of the input string. | codefeedback |
Write a SQL query to count the number of unique customers who purchased an item in a given month, while also including the total number of items purchased by each customer. Additionally, the query should return the average price of the purchased items for each customer.
Table name: "Orders"
Columns:
- order_id (integ... | codefeedback |
Complete the SQL query which finds the name, age, address, and number of orders placed by all female customers who live in the city "New York" and have placed more than 5 orders.
Table A (Customers):
name | sex | age | address
Table B (Orders):
customer_id | order_number | order_date | order_total | codefeedback |
Write a function to reverse the order of the four elements in the given list without using any built-in functions or methods. The time complexity of the solution should be O(1). | codefeedback |
Create a PHP script that can validate if a given string is a valid IP address, but without using any built-in functions or regular expressions. The script should only use basic string manipulation and comparison operations. Additionally, the script should also validate if the IP address belongs to a specific range of I... | codefeedback |
Write a SQL query to join two tables 'employees' and 'locations' on the key 'name' and return only the employees of age 25-35. Additionally, include the region of the city from the 'locations' table in the result.
Table A (employees):
id | name | city | age
Table B (locations):
city | region | codefeedback |
Write a user defined function to print the sum of two numbers, but the input numbers should be taken from the user. Additionally, the function should only use bitwise operations and not use any arithmetic operators or loops. | codefeedback |
Develop a script in JavaScript to validate an email address according to the following rules:
1. The email address must contain a minimum of 8 characters.
2. The email address must start with a lowercase letter.
3. The email address can only contain lowercase letters, numbers, and the following special characters: ! # ... | codefeedback |
Create a new method "listItems" which returns a list of strings. The method should take in a list of integers as input and return a list of strings where each string represents the corresponding integer in the input list, multiplied by 2. The method should have a time complexity of O(n) and should not use any built-in ... | codefeedback |
Write a Python function that takes in a list of integers and returns a new list that contains only the even numbers in the original list. The function should have a time complexity of O(n) and should not use any built-in Python functions or methods (such as filter or list comprehensions) that directly solve the problem... | codefeedback |
Please modify the CSS in the given HTML code to style the web page. The styled page should have the following features:
- The background color of the page should be set to a gradient of blue and purple.
- The title should be centered horizontally and vertically on the page.
- The title should have a font size of 40 pix... | codefeedback |
Write a JavaScript function that accepts two parameters - a number and a string - and returns a sentence with both parameters combined. The sentence should follow the format "The number [num] is associated with [str]". The number should be displayed as a Roman numeral.
The function should have a time complexity of O(l... | codefeedback |
Create a function in Python that takes in a positive integer as input and returns a list of all prime numbers up to that input value. The list must be sorted in descending order. The function should have a time complexity of O(n log log n). | codefeedback |
Please create a MySQL schema to store a table of products with the following requirements:
1. The table should have columns for the following product attributes:
- Product ID (unique identifier)
- Product Name
- Product Description
- Product Price
- Product Quantity
2. The Product ID should be an auto-... | codefeedback |
Write a code snippet that returns the root of a given binary tree, but with the additional requirement that the code should also calculate and return the sum of all the nodes in the tree. Assume that the nodes of the binary tree contain positive integer values.
```
class TreeNode:
def __init__(self, value):
... | codefeedback |
Write a code snippet in Java that sorts a given array of objects in ascending order. The objects in the array should be sorted based on a specific attribute, such as their names or IDs, in addition to their natural order. Additionally, implement the sorting algorithm yourself instead of using built-in sorting functions... | codefeedback |
Edit the following SQL statement to select all rows from the "users" table where the "country_id" is 2, the "level" is greater than 5, and the "age" is between 18 and 30, inclusive. Additionally, order the results in descending order based on the "score" column and limit the output to only the top 10 rows.
SELECT * FRO... | codefeedback |
Submit a valid Ruby program to remove all vowels from a given string of length less than or equal to 100 characters, "Hello$#@World!", and store the modified string in a new variable named "result". | codefeedback |
Write a JavaScript function to find the cube root of a number, without using the built-in `Math.cbrt()` function.
Requirements:
- The function should have a time complexity of O(log n), where n is the input number.
- The function should have a space complexity of O(1), i.e., it should not use any additional data struc... | codefeedback |
Write a function in C to find the corresponding letter for a given prime number within a given range of lowercase letters (a-z). The function should also handle cases where the prime number is negative or exceeds the range of possible corresponding letters. Additionally, optimize the function to have a time complexity ... | codefeedback |
Create a C++ code to display the following pattern.
1
232
45654
7890987
121214363241424
The number in each line should be generated based on the following rules:
- The first line contains the number 1.
- Each subsequent line should contain a sequence of numbers, where each number is the sum of the three numbers direc... | codefeedback |
Write a Java method to transform a String input into a String array with each element the length of 4. The input string must contain at least 10 characters and each character must be a lowercase alphabet letter. Additionally, the output array must be sorted in alphabetical order and each element must be unique. | codefeedback |
1. Create a new div element.
2. Set the id attribute of the div element to "main-container".
3. Create a text node with the content "Hello World!".
4. Append the text node as a child of the div element.
5. Get the reference to the parent element where you want to add the div element.
6. Check if the parent element exis... | codefeedback |
Implement a Java program to search for books in a library based on various criteria such as title, author, genre, publication year, and availability status.
In addition to searching for books, the program should also allow users to add new books to the library, update existing book information, and remove books from t... | codefeedback |
Create a function that takes two arguments, the lengths of two sides of a right triangle, and calculates and returns the length of the third side using the Pythagorean theorem in Python.
The Pythagorean theorem states that in a right triangle, the square of the length of the hypotenuse (the side opposite the right ang... | codefeedback |
Create a function in Python that takes as arguments two strings and returns a boolean indicating whether both strings are equal or not. The function should perform a case-sensitive comparison and consider whitespace characters. The strings must also not exceed a length of 100 characters and can only contain alphanumeri... | codefeedback |
Write a function in Java that takes an input string and changes the case of each letter to its opposite (i.e. upper case to lower case and vice versa). The function should also ignore any non-alphabetic characters and retain their positions in the final output string. Additionally, the function should also reverse the ... | codefeedback |
Create a program that replaces all occurrences of a given string with a new text in a given text file. The program should also keep track of the number of replacements made and output it at the end.
File: "input.txt"
Old Text: "Hello World"
New Text: "Hello Universe"
Additional requirement: The program should only r... | codefeedback |
Create a jQuery function that animates an element's background color from red to green over 3 seconds, but only if the element has a class of "animated". Additionally, ensure that the animation starts only when the element is in the viewport and the user has scrolled to a certain position.
To implement this, you can f... | codefeedback |
Categorize a given dataset into three classes, where each class should have an equal number of elements and the sum of the elements in each class should be equal. The dataset is limited to positive integers only. Additionally, the algorithm should optimize for minimizing the difference between the maximum and minimum s... | codefeedback |
You are given a string that contains only lowercase letters and spaces. Your task is to output a new string with all the vowels removed, the characters reversed, and all the spaces replaced with a specific character '*'.
Example:
Input: "hello world"
Output: "dlrwhll" | codefeedback |
You need to generate a random four-digit number without repeating any digit, and return it as a string. | codefeedback |
Construct an algorithm in pseudocode to sort a given array of numbers. The algorithm should sort the array in descending order and only use the bubble sort algorithm. Additionally, ensure that the algorithm handles duplicate numbers correctly, i.e., they should be sorted in descending order but maintain their original ... | codefeedback |
Edit the following class to make sure any variables created as part of the class cannot be modified by the program. Additionally, create a new method called "add" that takes two parameters and returns the sum of the two parameters. Make sure that this method cannot be modified or overridden by any child classes.
class... | codefeedback |
Construct a SQL query to get the name, age, and grade of the youngest student, where the grade is greater than or equal to 80, and the student must have at least 3 years of work experience in a relevant field. | codefeedback |
Implement a scientific calculator that takes a mathematical equation containing operators like addition, subtraction, multiplication, and division, as well as functions like sine, cosine, and square root. The calculator should handle equations with parentheses and prioritize the order of operations correctly. Additiona... | codefeedback |
Use the given data to print out the average of the numbers. However, you are not allowed to use any arithmetic operations or built-in functions to calculate the average. Instead, you must come up with an alternative algorithm to compute the average. The given data is [1, 7, 8, 10].
Additional Instructions:
1. You are ... | codefeedback |
Given a list of strings and a search string, check if the search string is present in any of the strings in the list. If it is present, return a boolean value. Additionally, if the search string is not present in any of the strings in the list, raise a ValueError.
strings = ['apple', 'banana', 'cherry', 'durian']
sear... | codefeedback |
Create a function in R that calculates the median of a given dataset [4.6, 8.9, 5.4, 7.2]. The function should handle datasets with up to 1000 elements and should also check for invalid inputs such as non-numeric values or missing values. Additionally, the function should be able to handle datasets with duplicate value... | codefeedback |
Construct a machine learning model in Python for the given dataset with the added requirement of achieving an accuracy of at least 90% on the test dataset. Additionally, you must implement a feature selection algorithm to identify the most relevant features for predicting income, considering potential interactions and ... | codefeedback |
Write a type annotation for a function that takes a list of integers as an input and returns a list of tuples, where each tuple contains the integer and a boolean value indicating if the integer is prime. The function should have a time complexity of O(n√m), where n is the number of integers in the input list and m is ... | codefeedback |
Compare the performance of two different neural network architectures on a custom dataset with added constraints. Two convolutional neural networks (CNNs) with different depth of layers have been trained on a custom dataset consisting of 10 classes and 10,000 images. The dataset is highly imbalanced, with each class ha... | codefeedback |
Write a sample program that performs text classification, ensuring that it can handle large datasets consisting of at least 10,000 text samples, each containing a minimum of 500 words. Additionally, your program should implement a feature that allows users to specify multiple classification categories for each text sam... | codefeedback |
Compute the weighted binary cross-entropy loss of a given classification problem, where each ground truth label is assigned a different weight and the predicted probabilities are not limited to the range [0, 1]. | codefeedback |
Write a function in Python to calculate the compound interest given the principal amount, rate of interest, number of years, and number of times interest is compounded per year.
Example inputs:
principal_amount = 1000
interest_rate = 0.10
num_years = 3
compounded_per_year = 12
Write a function that takes in these inp... | codefeedback |
Write a function in Python that takes in a list of integers and returns the sum of all the prime numbers in the list. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.