instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Implement a function in Swift to swap the values of two integer variables without using a temporary variable. The function should also handle swapping the values of two floating-point variables in addition to integers. The function should have a time complexity of O(1). | codefeedback |
You are given an array of strings. Code a JavaScript function to remove duplicate strings from the array. The function should also sort the strings in descending order based on their length. If two strings have the same length, their order should be determined by their lexicographic order.
Example:
Input:
["apple",... | codefeedback |
Given an array of objects, each containing a name and an age, and a search keyword, code a JavaScript function to check if the keyword exists in the array and is also present in the names of all objects whose age is greater than or equal to 18. Additionally, the function should handle cases where the keyword is in uppe... | codefeedback |
Design a C code to accept an array of integers from the user and find the second greatest number among them. The code should also handle the scenario where the array may contain duplicate numbers. | codefeedback |
Write a program in Python to implement a basic web crawler that can scrape and store information from multiple websites. | codefeedback |
Given a JSON object with nested arrays and objects, code a JavaScript function to convert the object into a query string. The function should only include key-value pairs that have non-null values and exclude any key-value pairs that have empty arrays or objects. Additionally, the function should sort the key-value pai... | codefeedback |
Codify a static HTML page such that when the page URL is accessed, it displays the message "Please enter your login details". Additionally, add a form with two input fields for username and password, and a submit button. Upon submitting the form, validate the entered credentials and display an appropriate message such ... | codefeedback |
Identify the ‘time and space complexity’ of an algorithm written in Java that calculates the sum of all elements in a list and then calculates the average of the sum. The algorithm should handle both positive and negative numbers and should exclude any duplicate elements in the list. Additionally, the algorithm should ... | codefeedback |
Code an assembly language program to calculate the sum of series 1 + 4 + 7 +.....+ (3*n-2), where n is a positive integer inputted by the user.
The program should first prompt the user to enter a positive integer value for n. It should then validate the input to ensure that it is indeed a positive integer. If the inpu... | codefeedback |
You are given a string representing an HTML code. Write a function to strip the tags from it. Additionally, make sure that the function handles nested tags correctly. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the input string. | codefeedback |
Given an array of numbers, code a Java program to find the highest number. The program should also handle the case when the array is empty and return an appropriate message. Additionally, the program should keep track of the number of times the highest number appears in the array and print this count along with the hig... | codefeedback |
Write a regex pattern to extract all words containing the letter 'a' or 'e' followed by a vowel from a given string. | codefeedback |
Write a program that implements a hash table data structure from scratch using only arrays and basic operations such as insert, delete, and search. The hash function should be a custom implementation and should have a time complexity of O(1) in the average case. Additionally, ensure that the hash table can handle colli... | codefeedback |
Use the list comprehension method to print the cube of all prime numbers from 1 to 100, excluding numbers divisible by 3 and 5. | codefeedback |
Rewritten Test:
Implement a function to insert a new node into a binary search tree. The function should take a key as input and should insert the key into the appropriate position in the tree. The time complexity of the function should be O(log n) on average.
Note: You should ensure that the binary search tree remai... | codefeedback |
Create a web application that allows teachers to input and manage student scores and grades. The application should have the following features:
1. User authentication: Teachers should be able to register and login to the application using their email and password. Only authenticated users should be able to access the... | codefeedback |
Generate an array containing prime numbers between 1 and 100, with a time complexity of O(n) and space complexity of O(1). | codefeedback |
Please implement a Java program to demonstrate the use of abstract classes and interfaces in a real-world scenario involving geometric shapes. Consider the following requirements:
1. Create an abstract class named "Shape" with the following attributes and methods:
- Attributes: color (string), filled (boolean)
-... | codefeedback |
Create a system call in C to generate a process tree, where each process has a unique randomly generated priority value between 1 and 100. The parent process should always have a higher priority than its child processes. The process tree should be constructed in a way that each child process has a maximum of 5 child pr... | codefeedback |
Create a program to list all the prime numbers between two numbers, but the program should also display a warning message if either of the input numbers is negative or if the first number is greater than the second number. Additionally, the program should only use a recursive function to find the prime numbers. | codefeedback |
Create a data structure to store information about multiple employees, including their personal details, such as name, address, and contact information, as well as their salary information, including basic salary, bonus, and deductions. Additionally, design a method to calculate the net salary for each employee after c... | codefeedback |
Write Javascript code to select all div elements with the class "container" that are also descendants of a div element with the id "main", and append a new div element with the class "highlight" to each selected div element.
The time complexity should be O(n), where n is the total number of div elements with the class... | codefeedback |
You are given two strings of lowercase letters, find the minimum number of operations required to make them equal. You can perform three types of operations:
1. Insert a character
2. Delete a character
3. Replace a character
The cost of each operation is equal to its ASCII value. Your task is to determine the minimum... | codefeedback |
Create a class to represent a student's report card. The report card should store the student's grades for multiple subjects, as well as calculate the average grade. The class should have the following methods:
1. `add_grade(subject: str, grade: float)`: Adds a grade for a specific subject. The subject should be a str... | codefeedback |
Write a SQL query to find the number of people below the age of 25 in the table 'people' who have a GPA above 3.5, are enrolled in at least two courses, and have a major in either Computer Science or Engineering. | 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 |
Write a Python function that takes as input an array of numbers and returns the maximum positive number. If there are no positive numbers in the array, the function should return -1. The time complexity of the function should be O(n), where n is the length of the array.
Additionally, the function should return the ind... | 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. | codefeedback |
Explain the importance of using functions in programming and provide a practical example where the use of recursive functions greatly simplifies the code. Additionally, analyze the time and space complexity of the recursive solution. | codefeedback |
Design a web page containing HTML/CSS containing at least 10 containers, where each container should display different content based on the user's interaction. The web page should have a responsive layout that adjusts to different screen sizes and should support at least 3 different screen sizes (desktop, tablet, mobil... | codefeedback |
Create a JavaScript object literal with four 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, and a key of address with a ... | codefeedback |
Find the maximum value of an array without using any built-in functions, with a time complexity of O(log n), a space complexity of O(1), and without using any loops or recursion.
[7, 9, -2, 15, 3] | 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. | 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 |
Develop an algorithm for reversing a string without using any reverse string methods. The input string will contain only alphabetic characters and will have a maximum length of 100 characters. Additionally, you must reverse the string in-place, without using any additional data structures. The algorithm must have a tim... | 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.
- Find the word with the lowest frequency.
- Find the k most frequent ... | codefeedback |
Given a string, find the length of the longest palindrome substring.
You are required to implement the following function:
```python
def longest_palindrome(s: str) -> int:
pass
```
## Input
- The input parameter is a string, `s` (1 <= len(s) <= 1000).
## Output
- Return an integer, the length of the longest pa... | codefeedback |
Create a filter to remove all integers 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 array. Additionally, the f... | codefeedback |
Create a function in JavaScript to recursively search for a specific key in a nested JSON object and return its value. The function should handle arrays of objects as well. If the key is not found, the function should throw an error with a custom error message. Additionally, the function should only search for the key ... | codefeedback |
Write a predicate function to check whether the given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. The function should ignore any spaces, punctuation marks, and capitalization in the string.
Additional Requirement: The functio... | 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 |
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, and are not part of the sales department. | codefeedback |
Write a code snippet to produce an XML result for a given input data structure. The input data structure may contain nested dictionaries and lists.
For example, given the following input data structure:
{
"key1": "value1",
"key2": {
"key2.1": "value2.1",
"key2.2": "value2.2"
},
"key3":... | 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 |
Write a CSS code to create a heading with red color font, where the heading should have a font size of at least 24 pixels and should be centered on the page. Additionally, the heading should have a background color of blue and a border of 2 pixels solid black. | 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. | codefeedback |
For the given matrix, calculate the determinant using a recursive algorithm.
Matrix:
1 2 3
4 5 6
7 8 9
Time Complexity Requirement: O(n!)
Space Complexity Requirement: O(n^2)
Error Reference Code:
def calculate_determinant(matrix):
# Check if matrix is a square matrix
if len(matrix) != len(matrix[0]):
... | codefeedback |
Convert this floating-point number to a 12-bit binary number, rounding to the nearest ten-thousandth. | 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. | 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 |
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 |
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 and evaluating th... | 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 |
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. | 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.
2. The user's nationality: If the user is from a country with a lower GDP than the average GDP of all countries, th... | codefeedback |
You are given an array of integers. Write a function to reverse the elements of the array without using any additional data structures and in-place.
#Additional Requirements#
1. Your solution should have a time complexity of O(n), where n is the length of the array.
2. Your solution should use only a constant amount o... | codefeedback |
Write a Python function that prints the square of each number in a given list of integers. Additionally, the function should only consider numbers that are greater than 10 and less than 100. The output should be sorted in descending order. | codefeedback |
List and explain at least 10 different HTML5 Semantic Elements and their respective attributes. | 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? | 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 |
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. | 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.
text = "Python is an easy to learn language, but Java is also a widely u... | 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 |
Write a function which prints out the odd numbers from a given list in descending order. The function should also display the sum of all the odd numbers.
For example, given the list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], the function should print:
9
7
5
3
1
The sum of the odd numbers is: 25
You should not use any built-i... | codefeedback |
Using list comprehension, create a new list that contains values less than 5 and are even. Additionally, for each value in the original list, add its square root rounded to the nearest whole number to the new list. Finally, sort the new list in descending order. The time complexity of the solution should be O(nlogn), w... | 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. | 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 |
Given two arrays of integers, write a Python function which is able to identify common elements. However, you are not allowed to use any built-in functions or libraries, such as set() or intersection(), to find the common elements. Additionally, you are not allowed to use any looping constructs such as for loops or whi... | codefeedback |
Edit the code to construct a bubble sort algorithm.
arr = [5, 2, 1, 7, 8]
The time complexity of the solution should be O(n^2), where n is the number of elements in the array.
The space complexity should be O(1), meaning no extra data structures should be used.
Additionally, modify the code to sort the array in desce... | 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 |
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 |
Construct a code that takes in an object and checks whether each property includes a certain value. The object should only contain strings and numbers.
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.
2. Iterate ove... | codefeedback |
Identify and correct the errors in the given code. Use a for loop instead of a while loop to print "Hello World!" 10 times. | 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. | 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 |
Create a SQL query to get the names and contact information 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. | 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 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 1000 (inclusive). If the input is not valid or falls outside the valid range, the program sho... | codefeedback |
Write an Android app to display a list of items from a local database, but the app should also include functionality to add, edit, and delete items from the database. Additionally, the app should implement a search feature that allows users to search for specific items in the list. The app should also have a feature th... | 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). | codefeedback |
Create a function to update the existing item of a dictionary with a new value. Additionally, if the value is a list or a dictionary, the function should check for any nested values and update them as well. The function should handle the following scenarios:
1. If the key exists in the dictionary and the new value is o... | 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.
#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 th... | 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 |
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).
In addition, the 'push'... | 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 |
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. | 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. | 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.
Example Output:
"Hello" - 2
"World" - 1
#Erroneous Code#
```python
def count_words(sentence):
words = sentence.split()
word_count = {}
for word in words:
... | 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 |
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'.
#Example#
Input:
remove_vowels("Hello World")
Output:
"Hll Wrld"
... | 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 also take into account the exceptions to the Gregorian calendar introduced by the Julian calendar reform in 1582. | 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.
Table Name: people
Columns: id (integer), name (string), age (integer), siblings (integer) | 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. | codefeedback |
Calculate the least common denominator of 12 and 18, but only using prime factorization. Additionally, handle cases where one or both of the numbers are negative. | codefeedback |
Write a program that takes an HTML file as input and extracts all the <img> tags and their corresponding alt attributes. The program should then display the images along with their alt text in a graphical user interface.
Note: You are not allowed to use any HTML parsing libraries or frameworks. You must implement the ... | codefeedback |
Given a set of numbers, find the second largest number from the set.
Input: A list of integers
Output: The second largest integer from the input list
Example:
Input: [2, 9, 10, 11, 5]
Output: 10
Constraints:
- The length of the input list will be between 2 and 10^5.
- The integers in the input list will be between... | 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 in the result set, and order the results by the average salary in descending order.
Hint: You may need to... | 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 SQL query to get the names and contact information of all employees who have at least 5 direct reports and have a total salary greater than $1,000,000, ordered by their total salary in descending order. | 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. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.