instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Explain the importance of using memoization in recursive functions and provide a practical example where the use of memoization greatly improves the efficiency of the code. Additionally, analyze the time and space complexity of the memoized recursive solution. | codefeedback |
Describe the runtime complexity of segment tree and provide an implementation in Java or C++ that supports lazy propagation. Additionally, explain the concept of lazy propagation and how it improves the efficiency of segment tree operations. Discuss the trade-offs and limitations of using lazy propagation in segment tr... | codefeedback |
Construct a SQL statement that updates the "products" table and sets the value of the "price" column to 10 only for products that have a quantity greater than 100. Additionally, the statement should exclude any products that have already been discounted with a price lower than 10. The statement should be optimized to h... | codefeedback |
Create a JavaScript object literal with six properties: a key of name with a value of a string containing at least 10 characters, a key of age with a value of a number between 18 and 65 (inclusive), a key of hobbies with a value of an array containing at least five different hobby strings, a key of address with a value... | codefeedback |
Create a hashtable in Python of size 10^7 and insert 10^6 randomly generated elements, each element being a string of length 10. | codefeedback |
Design a web page containing HTML/CSS and JavaScript that displays a grid of at least 20 containers. Each container should have a fixed width and height, and should display a different image. The grid should be responsive and adjust to different screen sizes, with a maximum of 4 containers per row on desktop, 3 contain... | codefeedback |
Write a function in Java to delete duplicate elements from an unsorted array of integers. The function should have a time complexity of O(n), where n is the length of the array.
In addition to deleting duplicate elements, modify the function to also return the number of unique elements in the array.
Example:
Input: ... | codefeedback |
Write a function in Python that takes in a list of integers and returns the sum of all the even numbers in the list. The function should have a time complexity of O(n) and should not use any built-in functions or libraries to calculate the sum. Additionally, the function should not use any loops or recursion to iterate... | codefeedback |
Please implement the `longest_palindrome` function which takes in a string as input and returns the length of the longest palindrome substring in the given string. You can assume that the input string will contain only lowercase alphabets and its length will not exceed 1000.
You are required to implement the following... | codefeedback |
Create a filter to remove all integers and duplicate elements from an array of mixed data types, while preserving the order of the remaining elements. The resulting array should only contain strings and floating-point numbers. If there are no strings or floating-point numbers left after the removal, return an empty arr... | codefeedback |
Design a responsive HTML document that displays a dynamic chart representing the sales of a particular item over a given time period. Implement a feature to allow users to filter the chart based on different criteria such as region, product category, or date range. Additionally, the chart should have interactive toolti... | codefeedback |
Design a data structure to track the frequency of words in a given text, while also maintaining the order of the words in the text. Additionally, the data structure should support the following operations:
- Find the word with the highest frequency in O(1) time complexity.
- Find the word with the lowest frequency in O... | codefeedback |
Create an SQL query to print the names, job titles, and departments of employees who are earning more than $50,000/year, have at least 5 years of experience in their current role, are not part of the sales department, and have not received any promotions in the last 2 years. | codefeedback |
Construct a code to get the last index of a given substring in a string. The substring should be case-sensitive and must be at least two characters long. The input string should contain at least one occurrence of the given substring. If there are multiple occurrences of the substring in the input string, the code shoul... | codefeedback |
Write a function in JavaScript that takes two strings as arguments and checks if the characters in the first string form a subsequence of the characters in the second string. The function should also handle cases where the characters in the first string do not appear in the same order in the second string. Additionally... | codefeedback |
Generate the Fibonacci sequence up to a given number n in Python, but also calculate the sum of all the Fibonacci numbers up to n. Additionally, your solution should not use recursion and should have a time complexity of O(n). | codefeedback |
Write a code snippet to produce an XML result for a given input data structure. The input data structure may contain nested dictionaries, lists, sets, and tuples.
For example, given the following input data structure:
{
"key1": "value1",
"key2": {
"key2.1": "value2.1",
"key2.2": "value2.2"
... | codefeedback |
Write a function that takes a floating-point number as input and returns a 12-bit binary number, rounded to the nearest ten-thousandth. | codefeedback |
Write a JavaScript function that takes a specific date and time as input and returns the number of milliseconds that have elapsed since that date and time until the current date and time. The function should account for leap years, time zone differences, and daylight saving time correctly. Additionally, the function sh... | codefeedback |
Please calculate the eigenvalues and eigenvectors of the given matrix using a power iteration algorithm.
Matrix:
1 2 3
4 5 6
7 8 9
Time Complexity Requirement: O(n^3)
Space Complexity Requirement: O(n^2)
Error Reference Code:
import numpy as np
def calculate_eigen(matrix):
# Check if matrix is a square matrix
... | codefeedback |
Write a code to delete all records in an MS Access table, but exclude any records where the value of a specific field is equal to a predetermined value and the value of another specific field is less than a certain threshold. Additionally, you need to implement the following logic:
1. Before deleting the records, prom... | codefeedback |
Write a JavaScript function that accepts a string argument and returns its capitalized value. However, you must also handle the case where the string contains numbers or special characters. If the string contains numbers or special characters, the function should remove them and only capitalize the alphabetic character... | codefeedback |
Code a React component that renders a button with the following requirements:
1. The button text should be "Submit" but displayed in uppercase letters.
2. The button should have a background color of #F44336 (Material Design red).
3. When the button is clicked, it should change its text to "Submitting..." and be disab... | codefeedback |
Implement a binary classification model using a Support Vector Machine algorithm to predict the likelihood of a customer subscribing to a bank's term deposit based on a given dataset. In addition to this, your implementation should handle imbalanced datasets by applying appropriate sampling techniques such as SMOTE or ... | codefeedback |
Write a C++ program for finding the maximum value in a Binary Search Tree (BST) using recursion. Your program should also include a function to delete the maximum value node from the BST and adjust the tree structure accordingly. Additionally, your program should handle cases where the maximum value occurs multiple tim... | codefeedback |
Write a Python function that calculates the sum of all prime numbers in a given list of integers. Additionally, the function should only consider numbers that are greater than 100 and less than 1000. The output should be sorted in ascending order. | codefeedback |
You are given an array of integers. Write a function to reverse the elements of the array in groups of k, where k is a positive integer. The function should reverse the elements of each group without using any additional data structures and in-place.
#Additional Requirements#
1. Your solution should have a time comple... | codefeedback |
Write a Java program that takes user input and determines their rating out of 10 based on the following criteria:
1. The user's age: If the user is below 18 years old, their rating is reduced by 2 points. If the user is above 65 years old, their rating is reduced by 1 point.
2. The user's nationality: If the user is fr... | codefeedback |
Create a Java method that takes an array of integers as an argument and returns the product of all the integers in the array. The method should have a time complexity of O(n), where n is the length of the array. However, you are not allowed to use any multiplication or division operators in your solution. Additionally,... | codefeedback |
Create a web page that includes a form with validation using HTML5 semantic elements. The form should have at least 5 input fields, each with its own unique validation requirement (e.g. one field should only accept numbers, another should require a specific format for a phone number). Additionally, the web page should ... | codefeedback |
Write a function which prints out the prime numbers from a given list in ascending order. The function should also display the product of all the prime numbers.
For example, given the list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], the function should print:
2
3
5
7
The product of the prime numbers is: 210
You should not use... | codefeedback |
Create a Linux shell script for managing network interfaces.
Instructions:
1. The script should display a menu with the following options:
a. List all available network interfaces
b. Display the status of a specific network interface
c. Restart a specific network interface
d. Exit the script
2. Implement a... | codefeedback |
Given a text string, write a function in Python to identify all the words that have more than 5 characters and are not repeated within the same sentence. Additionally, the function should also return the frequency of each unique word in the text. The function should be case-insensitive and ignore punctuation marks.
te... | codefeedback |
Using SQL, write a query to identify the student ID, name, and semester of the student who scored the highest marks in each subject across multiple semesters, and also rank the students based on their overall average marks across all subjects. Additionally, display the subject(s) in which the student scored the lowest ... | codefeedback |
Design a class named "Rectangle" that prints out the length, width, area, and perimeter of a given rectangle. Additionally, implement a method called "isSquare" that returns true if the rectangle is a square and false otherwise. The length and width of the rectangle should be positive integers between 1 and 1000. The c... | codefeedback |
Construct a code that takes in an object and checks whether each property includes a certain value. The object can contain strings, numbers, arrays, and nested objects.
The code should have the following steps:
1. Create a function that takes in two parameters: the object to be checked and the value to be searched for... | codefeedback |
Create a SQL query to get the names, contact information, and shipping addresses of all the customers who have purchased at least two products from a specific category, spent a total amount greater than $1000, and have made their purchases within the last 7 days. Additionally, the query should sort the results in desce... | codefeedback |
Create a loop which prints out the ASCII values of each character in a given input, a = 'Hello World!', without using any built-in functions or libraries that directly convert characters to ASCII values.
Additionally, you are not allowed to use the ord() function or any similar method to convert characters to ASCII va... | codefeedback |
Explain the use of the Huffman encoding algorithm and provide a Python code implementation to compress a given string using Huffman encoding. Additionally, implement a function to decompress the compressed string and retrieve the original string.
The Huffman encoding algorithm is a lossless data compression method tha... | codefeedback |
Construct a while loop that continuously adds all elements of a list until reaching a certain number. The sum must be calculated using a recursive function. The list must contain only positive integers. The maximum length of the list is 1000. The sum_num must be a positive integer less than or equal to 10,000. If the s... | codefeedback |
Build a secure and scalable REST API with Node.js that provides the real-time temperature and humidity data of a given location. The API should implement token-based authentication and rate limiting to prevent unauthorized access and mitigate potential attacks. Additionally, the API should support multiple languages fo... | codefeedback |
Create an HTML page that renders two checkboxes, a button, and a text input field using JavaScript. The text input field should have a maximum length of 10 characters and only accept numeric values. When the button is clicked, the input value should be validated to only accept positive numbers. If the input value is no... | codefeedback |
Create a function that converts a binary string to its corresponding decimal value. The function should handle the following scenarios:
1. If the binary string is empty or contains characters other than '0' and '1', the function should return an error message.
2. If the binary string is valid, the function should con... | codefeedback |
Construct a SQL query to find the list of customers with the highest average sales per transaction, considering only sales made in the last 3 months. Additionally, include only customers who have made at least 10 transactions in the last 3 months. | codefeedback |
Create a Java program to output the Fibonacci series up to the given number. The program should prompt the user to enter the number of terms in the series and validate the input to ensure it is a positive integer between 1 and 10^6 (inclusive). If the input is not valid or falls outside the valid range, the program sho... | codefeedback |
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(log n) and a space complexity of O(1), and must not use any loops or conditionals in the implementation. | codefeedback |
Create a code that takes two integer arguments and returns the sum of the two integers, but with the following additional requirements:
1. The code should not use any arithmetic operators (such as +, -, *, /) or built-in functions (such as sum()) to perform the addition.
2. The code should handle negative numbers and ... | codefeedback |
Create a class 'Stack' that has the following methods:
1. 'push': Adds an element to the top of the stack. The element should be an integer within the range of 1 to 1000.
2. 'pop': Removes and returns the element at the top of the stack.
3. 'max_stack': Returns the maximum element in the stack. The method should have ... | codefeedback |
Create an HTML webpage that displays a table containing a list of students and their corresponding grades. The webpage should include a button that allows the user to sort the table by the students' names in alphabetical order. Additionally, implement a search functionality that allows the user to search for a specific... | codefeedback |
Generate a list containing the cubes of the first ten prime numbers, where the product of the digits of each cube is a palindrome number. Additionally, the cubes must be arranged in ascending order in the list, and each cube must have at least three distinct prime factors. | codefeedback |
Given a sentence, capitalize each word in the sentence using string functions. The sentence can contain multiple words separated by spaces. However, you are not allowed to use any built-in string functions or methods that directly capitalize words or convert strings to title case.
To solve this problem, you can implem... | codefeedback |
Add a new column to a Pandas DataFrame called "age_group" that contains categorical values "young","middle-aged","elderly". Additionally, the "age_group" should be determined based on the following criteria:
- "young" for ages less than 25
- "middle-aged" for ages between 25 and 55 (inclusive)
- "elderly" for ages grea... | codefeedback |
Construct a class which instantiates objects with a given name, age, and address. Implement a method `get_name` which returns the name of the object, a method `get_age` which returns the age of the object, and a method `get_address` which returns the address of the object. Additionally, implement a method `set_name` wh... | codefeedback |
Construct a function that converts a given temperature from Celsius, Kelvin, or Rankine to Fahrenheit. However, the function should also be able to handle input temperatures in Fahrenheit, in which case it should convert it to Celsius, then to Kelvin, and finally back to Fahrenheit.
The function should round the outpu... | codefeedback |
Edit the following HTML string so that it sets the background color of the page to "blue", adds a CSS class to all paragraph tags with a specific id, and ensures that the modified HTML string is a valid HTML5 document with appropriate doctype, head, and body tags.
Additionally, you need to:
1. Use JavaScript to dynami... | codefeedback |
Write a code in Python to count the number of unique words in a given sentence and display each word along with its frequency in descending order. The code should be optimized for large input sizes.
Example Input:
sentence = "The quick brown fox jumps over the lazy dog."
Example Output:
"the" - 2
"quick" - 1
"brown" ... | codefeedback |
Define a function called remove_vowels that will take a string as an argument and returns the string with all the vowels removed. The string may contain uppercase and lowercase letters. Vowels include 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'. The function should have a time complexity of O(n) and a space comple... | codefeedback |
Create a SQL query to find the name and age of the oldest person who has at least 3 siblings and their age is a prime number in the database. Additionally, include the average age of their siblings in the result. You should also sort the result by the average age of siblings in descending order. | codefeedback |
Create a loop that prints 'hello' 10 times when ran. However, each time the word 'hello' is printed, it should be capitalized every other time starting from the second iteration. Additionally, the loop should be terminated if the word 'goodbye' is printed. Ensure that the loop is implemented using a nested loop structu... | 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. Additionally, the function should take into account the exceptions to the Gregorian calendar introduced by the Julian calendar reform in 1582. The function should also consider the variations in leap... | codefeedback |
Create a while loop that prints all the lowercase letters of the alphabet in reverse order, but the loop must terminate if the current letter is a vowel. Additionally, count the number of consonants encountered and print the count after the loop terminates. | codefeedback |
Edit the given SQL query to find the maximum salary of employees who have been with the company for at least 5 years, have not received any promotions in the last 2 years, and have a job title that starts with the letter 'S'. | codefeedback |
Calculate the least common denominator of 12 and 18, but only using prime factorization and without using any built-in prime factorization functions or libraries. Additionally, handle cases where one or both of the numbers are negative and also handle cases where the numbers are floating point numbers. | codefeedback |
Create a SQL query that finds the average salary of employees aged between 25 and 30, working in the Sales department, and have been with the company for at least 2 years. Additionally, include the department name, job title, and employee name in the result set, and order the results by the average salary in descending... | codefeedback |
Given a set of numbers, find the second largest number from the set. However, you are not allowed to use any sorting algorithms or built-in functions to solve this problem.
Input: A list of integers
Output: The second largest integer from the input list
Example:
Input: [2, 9, 10, 11, 5]
Output: 10
Constraints:
- T... | codefeedback |
Write a JavaScript function that takes in a string as input and converts all uppercase characters to lowercase characters, while also removing any whitespace characters in the string. The function should return the modified string.
Requirements:
- The function should have a time complexity of O(n), where n is the leng... | codefeedback |
Construct a JavaScript object with 10 key-value pairs, where each key is a string representing a category and each value is an array containing at least 5 elements. The elements in each array should be objects, and each object should have at least 3 properties. Additionally, each array should have at least one object w... | codefeedback |
Given a JSON object containing an array of fruits, each with a type, count, and color, find the total count of each type of fruit and display them in descending order based on the count.
{
"fruits": [
{ "type": "apple", "count": 10, "color": "red" },
{ "type": "orange", "count": 5, "color": "orange... | codefeedback |
Please implement a program that takes a list of HTML files as input and extracts all the <a> tags and their corresponding href attributes. The program should then display the links along with their href values in a graphical user interface.
Note: You are not allowed to use any HTML parsing libraries or frameworks. You... | codefeedback |
Create a MySQL statement to count the number of orders for each customer, excluding customers who have placed less than 5 orders in total, have at least one order with a total value higher than $1000, and have made their first order within the last 30 days. | codefeedback |
Given a matrix of integers, delete the row or column that contains the least number of prime numbers. If there are multiple rows or columns with the same minimum number of prime numbers, delete the one that appears first.
Additionally, after deleting the row or column, update the remaining elements in the matrix by su... | codefeedback |
Use Python to generate a random string of length N (where N is given as input) using lowercase alphabetic characters, uppercase alphabetic characters, and numeric digits. Additionally, the string should contain at least one uppercase alphabetic character, at least one lowercase alphabetic character, at least one numeri... | 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, returning the prime numbers in descending order if "start" is greater ... | codefeedback |
Construct a C++ class called "Student" with the following data members:
1. A string variable named "name" to store the name of the student.
2. An integer variable named "age" to store the age of the student.
3. An array of floating-point numbers named "grades" to store the grades of the student in different subjects.
4... | codefeedback |
Given a JSON string, transform it into an array while handling cases where the JSON string is nested or contains arrays as values. Additionally, handle cases where the JSON string contains custom data types and convert them into their appropriate representations in the array. Implement a function `jsonToArray` that tak... | codefeedback |
Suggest a way to create a loop of 10 elements in C# that calculates the product of the first 500 prime numbers and outputs the square root of the product. | codefeedback |
Write a code snippet for a function that deletes all occurrences of a specific element from a multi-dimensional array, without using any built-in array methods or data structures. The multi-dimensional array can have nested arrays of arbitrary depth.
Additionally, you should handle any other non-array elements within ... | codefeedback |
Given an array of integers, find the largest palindrome substring within the array and return its length. A palindrome substring is a sequence of characters that reads the same forward and backward. If there are multiple palindromes with the same length, return the one that appears first in the array.
For example, for... | codefeedback |
How to identify an email address from a given string using Regular Expressions and ensure that it is not part of a URL, inside a comment or string literal, and also does not include any special characters? Additionally, implement a function that returns the domain name of the email address, without using any built-in s... | codefeedback |
Explain the concept of hashing and how it relates to dictionaries in Python. Additionally, write a Python function that takes a list of words as input and returns a dictionary where the keys are the unique words and the values are the number of times each word appears in the list. The function should use a hashing algo... | codefeedback |
Create a Flask endpoint for displaying a paginated list of items from a database, sorted in descending order of price. In case of a tie, sort by name in ascending order.
Table name: 'items'
Columns: id (integer), name (string), price (float)
Requirements:
1. The endpoint should accept two query parameters: 'page' and... | codefeedback |
Create a web application that displays a table with five columns: Name, Age, Gender, Address, and Email. Each row should represent a person's information. The table should be sortable by any column when the corresponding column header is clicked. Additionally, the application should allow the user to filter the table b... | codefeedback |
Explain the difference between a system call and a library function. Discuss the advantages and disadvantages of using system calls and library functions in a C program. Provide an example of a system call and a library function in the C programming language, and explain how they are used in practice.
Additionally, wr... | codefeedback |
Design a React component to display a button that increments a counter by a random number between 1 and 100. The component should also display the current value of the counter. Additionally, the component should have a reset button that sets the counter back to 0.
However, there are a few additional requirements:
1. ... | codefeedback |
Using a while loop, print out the keys and values of a given dictionary in reverse order, but only for the keys that have a length greater than 5. Additionally, ignore any keys that contain the letter 'e'. | 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, if a required tag is missing, or if the tag values do not match a specified data type.
Example input:
<xml><title>HelloWorld!</title><bod... | codefeedback |
Using a try-except statement, write a Python code to handle multiple types of exceptions including ValueError, TypeError, and IndexError, which may arise if the input is not a number or if it is out of range. Additionally, implement a loop that allows the user to continue entering inputs until a valid number is provide... | codefeedback |
Given two strings, determine whether the first string is a substring of the second string, considering the additional requirements.
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 ... | 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 |
Explain how constructor chaining works in Java when there are multiple inheritance levels involved, taking into consideration the added constraint that one of the parent classes is an abstract class. Provide an example code snippet to demonstrate the concept, ensuring that the code includes at least one method override... | codefeedback |
Convert a given number from degrees to radians.
Write a function called `degrees_to_radians` that takes in an integer representing the number of degrees and returns a float representing the corresponding value in radians.
You should assume that the input will be a valid integer between -360 and 360.
Your function s... | codefeedback |
Construct a switch statement to return either "Nick" or "Jack" based on the value of the input. The input must be a non-empty string containing only lowercase letters. The output must be a string enclosed in double quotes. The switch statement must have at least ten cases. The program should handle both uppercase and l... | codefeedback |
How would you use a while loop to calculate the factorial of a given number, while also ensuring that the calculation is only performed for prime numbers between 1 and 100? | 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, the average salary of all employees in the company, the maximum salary among all em... | codefeedback |
Write a program that performs a case-insensitive substring search with the following additional constraints and requirements:
- The substring should only be considered a match if it is surrounded by spaces, punctuation marks, or numbers.
- The search should return the index of the first occurrence of the substring, or ... | codefeedback |
Create a program to find the maximum length common subsequence of two given strings. The subsequence should not only be the longest, but it should also have the highest frequency of occurrence in both strings. Additionally, the subsequence should consist of distinct characters only.
String1: "abcdgf"
String2: "abcdhf... | codefeedback |
Create an array of 10 prime numbers, where each element is a prime number greater than 100. Additionally, ensure that the sum of all the elements in the array is a prime number greater than 1000. | codefeedback |
Write a SQL query that returns all records from a table where the value in the "email" column contains the "@" symbol, the length of the email is greater than 5 characters, and the domain of the email is a valid domain. Additionally, the query should exclude any records where the domain name is a common disposable emai... | 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 and less than or equal to 1000.
- The program should handle... | codefeedback |
Read the two given positive integers and print the larger one. However, you are not allowed to use any comparison operators (such as > or <) or any arithmetic operators (such as + or -) in your solution. Additionally, your solution must have a time complexity of O(1) and must not use any built-in functions or libraries... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.