instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
## Problem ##
You are given a string, and you need to write a function that performs the following operations on the string:
1. Remove all duplicate characters.
2. Sort the remaining characters in ascending order based on their ASCII values.
Write a function `remove_duplicates_and_sort` to solve the problem. The func... | codefeedback |
Write a Javascript code to check if the given number is a prime number. Additionally, the code should also check if the number is a perfect square. The code should have a time complexity of O(sqrt(n)) for prime number checking and a space complexity of O(1). | codefeedback |
Given a string, write a Python program to find the first non-repeating character in it, without using any built-in Python functions or libraries. Additionally, the program should also handle cases where the input string contains special characters or numbers.
input_str = "aaaaabbbbccc@@@1111&&&" | codefeedback |
Construct a regular expression to extract all words from a given string that start with a specific letter and contain at least one uppercase letter. The specific letter should be case-sensitive and the extracted words should be in lowercase.
input_str = "The Quick brown fox Jumped over the lazy Dog" | codefeedback |
Write an algorithm to perform binary search on a sorted array that contains duplicate elements. The algorithm should find the first occurrence of a target element and return its index. If the target element is not present in the array, the algorithm should return -1. Ensure that the time complexity is O(log n) and the ... | codefeedback |
Create a JavaScript function that takes an array of numbers and returns the kth smallest element from the array, where k is an input parameter to the function. However, the function should only iterate through the array once. | codefeedback |
Construct a regular expression to check if a string begins with a given substring, ends with a specific word, and contains a specific number of digits in between. | codefeedback |
Construct a SQL query to find all columns in a table called "customers" where the first name is equal to 'John', the last name is equal to 'Doe', and the age is greater than 30. | codefeedback |
Write a query in MongoDB to find all the documents in the collection "Books" where the "author" field starts with "John" and ends with "Smith". | codefeedback |
Write a C++ code to find the longest common substring in two strings, but the substring must be at least 5 characters long, contain at least one digit, and be palindromic. | codefeedback |
Write a C++ function to find the maximum element in an array of integers. The function should handle negative numbers and return the maximum element as an integer.
You should implement the function using a divide-and-conquer approach. Divide the array into two halves and recursively find the maximum element in each ha... | codefeedback |
Count the number of unique words in this sentence using Python.
This sentence has a total of six unique words. Additionally, you should also remove any punctuation marks from the sentence before counting the unique words. | codefeedback |
Write a query in SQL to select all the rows from table Books and display only the books that were published in the last 5 years and have an average rating of at least 4.5. | codefeedback |
What is data transformation, how is it used, and provide an implementation for a data transformation algorithm that converts a string into an integer, considering edge cases and handling errors appropriately.
Write a function called `string_to_integer` that takes a string as input and returns the corresponding integer... | codefeedback |
Generate a 15-digit random number using Python. The number must be prime and contain at least one repeated digit. | codefeedback |
Write a Java program to find the kth largest element in a given array of integers, where k is a user-inputted value between 1 and the length of the array. You are not allowed to use any built-in functions or libraries for sorting or finding the maximum value. | codefeedback |
Create a method in Java to return the largest prime number less than a given number. The method should have a time complexity of O(log(n)^2), where n is the given number. Additionally, the method should have a space complexity of O(1). | codefeedback |
Compare two strings character-by-character and return the number of differences between them using Java. However, you are not allowed to use any built-in Java methods or libraries for string comparison. Additionally, ensure that your solution has a time complexity of O(n) and a space complexity of O(1), where n is the ... | codefeedback |
Given a string s, write a function to check if the string is a palindrome. The function should ignore any non-alphanumeric characters and should be case insensitive. Additionally, the function should return the number of palindrome substrings found within the given string. The palindrome substrings must be at least 3 c... | codefeedback |
Write a PHP program to find the sum of all prime numbers in an array.
Additional Requirements:
- The program should have a time complexity of O(n√m), where n is the size of the array and m is the maximum element in the array.
- The program should not use any built-in functions or libraries to check if a number is prim... | codefeedback |
Edit the Java code to filter out the persons whose age is a prime number and whose name contains at least two vowels.
List<Person> persons = new ArrayList<>();
for (Person person : persons) {
if (isPrime(person.getAge()) && hasAtLeastTwoVowels(person.getName())) {
System.out.println(person.getName());
... | codefeedback |
Implement a function in JavaScript to calculate the average of all elements in an array. The array may contain positive and negative integers, as well as decimal numbers. The length of the array can vary from 1 to 1,000,000 elements. Your solution should have a time complexity of O(n) and a space complexity of O(1).
A... | codefeedback |
Update the existing HTML structure to add a new div class named "container" inside the body element, and make sure that the container div has a minimum width of 800 pixels. Additionally, the container div should have a maximum width of 1200 pixels and should be centered horizontally on the page. | codefeedback |
Generate a random string of length N, where N is a positive integer input by the user, using Python. The string should consist of lowercase letters, uppercase letters, digits, and special characters. Additionally, the string should not contain any repeated characters. | codefeedback |
Write a code fragment to find the most frequent element in an array, excluding any elements that occur less than three times. The array must contain at least 20 elements and the output should be in descending order of frequency. Additionally, you should implement the solution in a single pass without using any addition... | codefeedback |
Generate an array with the first 50 prime numbers. | codefeedback |
Can you explain the concept of continuation-passing style (CPS) and provide an example of how it can be used to solve a specific problem in an imperative programming language such as C++ or Java? | codefeedback |
Please provide a new programming test question with a higher level of difficulty. | codefeedback |
Write a JS program that takes a number n and prints out the first n Fibonacci numbers in reverse order. Ensure that the program includes error handling for invalid input, such as non-numeric values or negative numbers.
Additionally, implement the program in a way that avoids calculating the Fibonacci numbers multiple ... | codefeedback |
Design a JSON structure for a calendar application that includes the following fields:
- "event_id": a unique identifier for each event
- "name": the name of the event
- "description": a description of the event
- "start_date": the start date and time of the event in ISO 8601 format
- "end_date": the end date and time ... | codefeedback |
Convert the given binary string to its corresponding decimal number. However, you are not allowed to use any built-in functions or libraries for converting binary to decimal. You must implement your own algorithm to solve the problem.
Additionally, your algorithm must have a time complexity of O(n), where n is the len... | codefeedback |
Write a Python code snippet to print the pyramid structure with the given number of lines, where each line consists of consecutive prime numbers.
Example:
Input: 5
Output:
2
3 5
7 11 13
17 19 23 29
31 37 41 43 47 | codefeedback |
Create a CSS style to set the background color of a div class "sample" to a random color from a pre-defined list of colors. Additionally, the background color should change every time the page is refreshed or the div is clicked. However, the random color generated should be a light shade, meaning it should have a high ... | codefeedback |
Write an SQL statement to select the name, city and country of all stores, but exclude any stores located in countries starting with the letter "A" and ending with the letter "Y". | codefeedback |
Find the index of the given word in the sentence. The sentence should contain at least 10 words and should not exceed a maximum length of 100 characters. The word should only be considered a match if it appears as a complete word, not as part of another word. Additionally, the word should be case-insensitive when compa... | codefeedback |
Create a list of three-word phrases using each of the six words ('apple', 'bear', 'cat', 'dog', 'elephant', 'fish'). The first word in each phrase should be a noun, the second word should be a verb, and the third word should be an adjective. Additionally, each phrase should contain at least one word that starts with a ... | codefeedback |
You need to find the largest subset of an array that sums up to a given value. The array may contain negative numbers and the target value can be negative as well. Additionally, the array can contain duplicates and the target value can be a floating-point number. You need to return the subset in descending order based ... | codefeedback |
Summarize the given paragraph in < 100 words, ensuring that the summary includes information about Ada Lovelace's contributions to the field of computer programming and her relationship with Charles Babbage. Additionally, the summary should mention the year in which Lovelace wrote a detailed description of the Analytic... | codefeedback |
Reverse a string using Python code and without using any built-in string reversal functions, slicing, or any additional data structures. Additionally, ensure that the solution has a time complexity of O(n), where n is the length of the string. | codefeedback |
Explain the purpose of try-catch-finally statement in JavaScript and provide an example of how it can be used to handle different types of errors. Additionally, discuss the differences between throwing an error using `throw` keyword and creating a custom Error object using the `Error` constructor function. | codefeedback |
Sort the given list of numbers in descending order.
[11, 9, 7, 5]
Return the sum of the first and second elements of the sorted list as the largest number. | codefeedback |
Calculate the square root of the given number and round it to the nearest integer. The input number will always be a positive integer less than or equal to 10^9. The time complexity of your solution should be O(log(N)), where N is the input number. | codefeedback |
Construct an array of objects with the fields "name", "age", and "gender". Each object should also have a nested array called "hobbies" which can contain multiple strings representing the person's hobbies. Additionally, add a method to each object called "introduce" that prints out a string introducing the person's nam... | codefeedback |
Write a JavaScript code to print the first 20 terms of the Fibonacci series, but exclude any terms that are divisible by both 3 and 5. Additionally, calculate and print the sum of the remaining terms. | codefeedback |
Create a MySQL table 'employees' with columns name, age, department, salary, hire date, and employee ID. Additionally, include a primary key for the table.
Ensure that the name column only allows values that are not null and have a maximum length of 50 characters.
The age column should only accept integer values betw... | codefeedback |
Write a Python function to create a two-dimensional array of specified dimensions, ensuring that all elements in the array are unique and in ascending order.
#Difficulties added#
- Ensuring that the elements in the array are in ascending order adds an additional constraint to the problem.
- The function should have a ... | codefeedback |
Write a Python function to generate the powerset of a given list, where the list may contain duplicate elements. The output should not contain any duplicate subsets. The function should return the powerset in lexicographical order. | codefeedback |
Create a MongoDB query for finding a record in the collection 'books' that contains a specific value for a given field and satisfies the following additional constraints: the title field must start with a capital letter, the author's name must contain the letter 'a' and the publication date must be after January 1st, 2... | codefeedback |
Write a Python function to compute the maximum value for each key in a given dictionary, but only if the value is an integer, divisible by 3, and also contains a prime number in its prime factorization.
d = {'a': 12, 'b': 20, 'c': 30} | codefeedback |
Write a Python function to replace all the occurrences of a given substring with another, but with the following additional constraints:
1. The function should be case-insensitive, meaning it should replace occurrences of the substring regardless of whether they are in uppercase or lowercase.
2. The function should n... | codefeedback |
Write a 'dockerfile' that includes instructions for installing a specific version of a software package and configuring it to run as a service in the background. Additionally, the software package should be installed from a non-standard source, such as a private repository or a specific URL. | codefeedback |
Write a query for filtering an array of objects in a MongoDB collection by their 'age' field. The collection is named 'users' and the filter should return objects with age greater than or equal to 18 and a 'gender' field that is not equal to 'female'. | codefeedback |
Name three Python libraries specifically used for sentiment analysis in social media data. Your solution should include a custom function to preprocess the social media data by removing stop words and performing stemming. Additionally, you must implement a feature extraction technique such as TF-IDF or word embeddings ... | codefeedback |
Describe how to debug a multithreaded C++ program using GDB, with at least five concurrent threads, where each thread is performing a different task and interacting with shared resources. | codefeedback |
Implement a class hierarchy in Python for a zoo management system. The system should have a base class called "Animal" with the following attributes: name, age, and species.
Create derived classes for different types of animals such as "Mammal", "Bird", and "Reptile". Each derived class should have additional attribu... | codefeedback |
Change the following code snippet to generate a random floating-point number from 0 to 100, and then round it to the nearest multiple of 5. After rounding, convert the result to an integer and store it in a variable named "roundedNumber". Finally, print the value of "roundedNumber" to the console. | codefeedback |
Describe in detail the components of a machine learning pipeline specifically designed for sentiment analysis of social media data, including the preprocessing steps, feature extraction techniques, and the algorithms commonly used for classification. Additionally, provide a justification for the choice of each componen... | codefeedback |
Suggest the best practice for minimizing the risk of SQL injection attacks, while also ensuring optimal database performance. Explain the steps involved in implementing the suggested practice and discuss any potential trade-offs or limitations. Additionally, provide examples of real-world scenarios where the suggested ... | codefeedback |
Convert the following strings to lower case and count the number of vowels in each string. The input strings may contain punctuation marks and special characters.
s1 = "Hello World!"
s2 = "HELLO WORLD!!!"
Time Complexity Requirement: O(n)
Space Complexity Requirement: O(1)
Note: You can assume that the input strings ... | codefeedback |
Given a string consisting of words separated by commas, reverse the order of the words and return the modified string.
Example:
Input: "Hello,World"
Output: "World,Hello"
Approach:
1. Initialize an empty list called "words".
2. Split the input string at every comma and store the resulting substrings in the "words" li... | codefeedback |
Write a SQL query to find the names of customers who have ordered products and have made a purchase in the last 30 days, but exclude customers who have also placed an order for a specific product within the last 7 days. | codefeedback |
Describe the steps of creating an application using the Flask framework, including setting up routes, handling forms, implementing authentication and authorization, and integrating a database. Additionally, provide an example of a common error that beginners may encounter when using Flask with a database and explain ho... | codefeedback |
Increase the difficulty by adding an additional requirement to the programming task:
- Purge all rows from the following dataframe that have a negative value in the Age column and sort the remaining rows in descending order based on the Age column. Then, add a new column called 'Category' to the dataframe. The 'Catego... | codefeedback |
Print the first 5 elements of the following list in reverse order, skipping any even numbers.
my_list = [2, 4, 6, 8, 10, 12, 14]
#Reasoning Steps#
1. Create an empty list called "reversed_list" to store the reversed elements.
2. Iterate over the "my_list" starting from the last element and ending at the fifth element.... | codefeedback |
Construct a Java program for sorting a given array in ascending order using the Bubble Sort algorithm.
Additional Information:
- The Bubble Sort algorithm works by repeatedly swapping adjacent elements if they are in the wrong order. This process is repeated until the array is sorted.
- You are required to implement t... | codefeedback |
Define a function that takes a list of positive integers as input and returns a list of all odd numbers greater than 10 and less than 100, while also ensuring that the returned list is sorted in ascending order. The function should handle cases where the input list is empty and should raise a ValueError if any negative... | codefeedback |
Write a C++ class to represent a date, including methods to perform various operations and validations on the date.
The class should have the following attributes:
- Integer variables to store the day, month, and year of the date.
The class should have the following methods:
1. A constructor to initialize the date wi... | codefeedback |
Create a program to parse a given string and return a dictionary with all the words and their frequency. The program should ignore any words that are less than 3 characters long or that contain any non-alphabetical characters. Additionally, the program should handle cases in a case-insensitive manner and count words wi... | codefeedback |
Count the number of unique prime numbers in the following list. The solution should have a time complexity of O(n), where n is the length of the list. Additionally, the solution should not use any built-in functions or libraries to check for prime numbers.
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | codefeedback |
Create a new dictionary with the requirement that all keys must be integers and all values must be strings. The dictionary should also support the following operations:
1. Add an entry to the dictionary with a given key and value.
2. Retrieve the value associated with a given key.
3. Update the value associated with a... | codefeedback |
Write a Python function that takes in two lists of integers and returns a new list containing only the common elements between the two input lists. The function should have a time complexity of O(n^2), where n is the length of the longer input list.
list1 = [1, 2, 3, 5, 7, 9, 10, 11, 12]
list2 = [2, 3, 4, 5, 6, 8, 9, ... | codefeedback |
Create a pandas dataframe from the following dictionary. The 'Name' column should contain 10,000 unique names randomly generated using a combination of letters. The 'Age' column should contain 10,000 randomly generated ages between 18 and 65. Additionally, add a 'Gender' column that randomly assigns each individual a g... | codefeedback |
Create a function to find the greatest common divisor of two numbers in Python without using any built-in functions or modules that directly calculate the greatest common divisor.
However, the function should now have a time complexity of O(log(min(a,b))) and space complexity of O(1), where 'a' and 'b' are the input n... | codefeedback |
Using Python, create a function to check if a given string contains at least one uppercase letter, one lowercase letter, and one numeric digit. Additionally, the function should return the number of uppercase letters found in the string. Please note that the input string may also contain special characters and the func... | codefeedback |
Sort the following list of integers in descending order. The list may contain duplicates and have a length of up to 10^6. Implement an efficient algorithm that uses O(1) extra space and runs in O(n log n) time complexity, where n is the length of the list. Additionally, you are required to remove any duplicate elements... | codefeedback |
Calculate the sum of all even elements in a given list of positive integers using Python. The list should contain at least 10 elements and each element should be less than or equal to 100. Find the sum only if the list has more even elements than odd elements and the sum should be greater than 100. Otherwise, output "N... | codefeedback |
Sort the given list of numbers in ascending order using Python.
numbers = [3, 5, 7, 1, 2]
Provide a piece of erroneous code as a reference to increase misdirection:
```python
def bubble_sort(numbers):
n = len(numbers)
for i in range(n):
for j in range(0, n-i-1):
if numbers[j] > numbers[j+... | codefeedback |
Using Python, create a function that takes in an integer n and returns a list containing the first n prime numbers.
The function should have a time complexity of O(n^2) or better and should not use any external libraries or functions for prime number generation.
Additionally, the function should not use any iterative... | codefeedback |
Compute the result of the following mathematical expression in Python, while also ensuring that the final result is rounded to the nearest whole number. Additionally, you should implement the calculation logic as a recursive function instead of using the built-in arithmetic operators. (4 + 5 * 7 - 9) / 2
Restrictions:... | codefeedback |
Write a Python function to find the intersection between two lists, where the elements in the intersection should appear in the same order as they appear in the first list. Additionally, the function should only consider elements that occur consecutively in both lists.
list1 = [1, 2, 3, 5, 7, 3, 4, 5, 6]
list2 = [3, 4... | codefeedback |
Find the longest palindrome in a given string using Python. The palindrome should consist of at least 5 characters and ignore any whitespace or special characters. Additionally, you are not allowed to use any built-in functions or libraries for string manipulation. Your solution should have a time complexity of O(n^2) ... | codefeedback |
Create a Python program to find the maximum value in the given array. However, you are not allowed to use any built-in functions or libraries to find the maximum value. You must implement your own algorithm to solve this problem. The array will contain only positive integers. Additionally, your algorithm should have a ... | codefeedback |
Write a JavaScript code to eliminate any symbols and numbers from a given string, while preserving the spaces and retaining the order of the remaining characters. Additionally, convert all uppercase letters to lowercase and remove any duplicate characters from the resulting string. | codefeedback |
Modify the following function to return the number of unique elements in a given array, without using any additional data structures such as arrays, hash maps, or sets. Additionally, the solution should have a time complexity of O(n) or less.
int count_unique(int array[], int n)
{
int count = 0;
int i;
... | codefeedback |
Write a SQL query to join two tables on a specified condition and display only the rows where the sum of the age and marks is greater than 100. Additionally, only include rows where the class in Table 2 is greater than 10.
Table 1:
id name age
1 a 15
2 b 18
3 c 20
Table 2:
id class marks
... | codefeedback |
Create a function to find the total area of a triangle, given its base, height, and the lengths of its three sides. The function should also check if the triangle is valid or not. A triangle is valid if the sum of the lengths of any two sides is greater than the length of the third side.
Function Signature: `def find_... | codefeedback |
Increase the difficulty of the test by requiring the use of functional components instead of class components.
#Given Test#
Improve the following React component to render a link with the text "Visit us Here". When the link is clicked, it should display an alert with the message "You have visited us!".
```javascript
... | codefeedback |
Create a C++ code to find the average of n numbers. However, the program should ignore any numbers that are prime or divisible by 3. If all the numbers provided are invalid, the program should display an error message and terminate. | codefeedback |
Edit the following function so that it counts the prime numbers in the given array. The function should have a time complexity of O(n * sqrt(m)), where n is the length of the array and m is the maximum value in the array.
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | codefeedback |
Implement a Java program for finding the index of the first occurrence of a target element in a sorted array. The array can contain duplicates.
Requirements:
- The time complexity of your solution should be O(log n), where n is the size of the array.
- The space complexity of your solution should be O(1), i.e., it sho... | codefeedback |
Write a shell script to prompt a user for their name, age, favorite color, and favorite animal. Display a personalized message that includes their name, age, and a statement about their favorite color and favorite animal. Additionally, store this information in a file named "user_info.txt" in a formatted manner.
The s... | codefeedback |
Create a Java program to check for a palindrome.
In addition to checking for palindromes, the program should also account for special characters, spaces, and letter case. For example, "A man, a plan, a canal: Panama" should be recognized as a palindrome.
Write a program that takes a string as input and determines whe... | codefeedback |
Create a function in Python that takes in a list of integers as input and prints out a stringified version of the list, where each integer is squared, converted to hexadecimal, and then reversed.
#Explanation#
To increase the difficulty, I have added an additional step of reversing the hexadecimal representation of e... | codefeedback |
Create a program that iterates through a list of integers and prints out each element along with its index position. Additionally, implement a condition to skip the iteration if the element is divisible by both 3 and 5. The program should also keep track of the total number of iterations skipped due to this condition. ... | codefeedback |
Design a PHP code snippet to create a scientific calculator that includes advanced mathematical functions such as exponential calculations, logarithms, trigonometric functions, and complex number operations. Additionally, the calculator should have the ability to handle user input validation, handle errors gracefully, ... | codefeedback |
Write a MySQL query to find the highest salary of each department, but exclude departments with less than 5 employees and only include departments where the average salary is greater than 50,000. | codefeedback |
Write a function in Python to calculate the value of "e" to 4 decimal places, without using any built-in math functions or libraries. Additionally, the function should be able to handle large inputs and efficiently compute the value of "e" within a reasonable time frame. | codefeedback |
Write a Python code to calculate the sum of natural numbers up to n, but without using any loops, recursion, or built-in functions like sum() or range(). | codefeedback |
Create a function to check if a specific item is present in a sorted list of integers. The function should return the index of the item if it exists in the list and -1 otherwise. Additionally, the function should have a time complexity of O(log n), where n is the length of the list.
To achieve this, you can use the bi... | codefeedback |
Write a SQL query to display all products in the database which have not been sold yet and have a price higher than $1000, while also sorting the results in descending order based on the product's popularity score. The popularity score is calculated based on the number of times the product has been viewed, with higher ... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.