instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Generate an array of the first 10 Fibonacci numbers using any programming language. Ensure that your solution has a time complexity of O(n), where n is the number of Fibonacci numbers generated. Additionally, implement the solution using a recursive approach. | codefeedback |
Create a recursive function that takes a positive integer as input and outputs its prime factors in descending order. The function should have a time complexity of O(sqrt(n)), where n is the input number. | codefeedback |
Write a class that has two methods: one to return the smallest element in a given list of integers using a linear search algorithm, and another to return the smallest element using a selection sort algorithm. The class should handle the following additional requirements:
1. The methods should handle an empty list and ... | codefeedback |
Write a MySQL query to select the 10 employees with the highest average salary from the Employees table. Employees table is defined as: (employee_id int, first_name varchar(255), last_name varchar(255), age int, salary int).
Additionally, exclude any employees who have been with the company for less than 5 years. The ... | codefeedback |
Merge two binary trees t1 and t2 into a new binary tree. The merged tree should have the following properties:
1. The value of a node in the merged tree is the sum of the values of the corresponding nodes in t1 and t2.
2. If a node exists in one tree but not in the other, the corresponding node in the merged tree shou... | codefeedback |
Please find an algorithm to determine if a given set of strings is a palindrome. The strings in the set are composed of only lowercase English alphabets and the maximum length of each string is 100. The palindrome test should be case-insensitive, meaning that strings that are the same when their case is ignored should ... | codefeedback |
Given a string s and an integer k, find the kth largest character of s. The characters in s are guaranteed to be ASCII characters.
Constraints:
- The length of s is at most 10^6.
- 1 <= k <= the number of unique characters in s.
Example:
Input:
s = "abcdddeeeefffff"
k = 3
Output:
'd'
Explanation:
The unique charac... | codefeedback |
Write a program that takes a list of web page components as input and outputs the purpose and functionality of each component. Each component should have a unique identifier and can be one of the following types: header, navigation menu, content section, sidebar, footer. The program should also allow the user to add ne... | codefeedback |
You are working on an e-commerce platform and need to keep track of the list of items purchased by each customer. In order to efficiently manage this information, you need to determine the most appropriate data structure to use.
Describe in detail the data structure you would choose and explain why it is the best choi... | codefeedback |
Create a function in C# which takes a string as an input and returns a boolean value indicating if the string is a palindrome or not. However, the function should also ignore any non-alphanumeric characters (such as spaces, punctuation, and symbols) and should be case-insensitive. Additionally, the function should cons... | codefeedback |
Generate a random phone number using random numbers in Python, ensuring that it follows the format (XXX) XXX-XXXX. Additionally, the generated phone number should not start with the digits 0 or 1, and the last four digits should not be a repeating sequence (e.g. 1111, 2222, etc.). | codefeedback |
Write a C++ statement to create an array of size between 10 and 20, where all elements are non-negative integers and have a maximum value of 100. Additionally, ensure that the sum of all the elements in the array is divisible by 5. | codefeedback |
Create a program in C++ which takes a pair of arrays as input and returns the sum of the corresponding elements in the arrays.
The program should have the following requirements:
1. The input arrays should have the same length.
2. The input arrays can have a maximum length of 10^6.
3. The elements in the input arrays ... | codefeedback |
Create a table in PostgreSQL called "person" with the following columns: id (integer), name (string), age (integer), address (string), salary (float), and hire_date (date). The table should have a primary key constraint on the "id" column and a unique constraint on the "name" column. Additionally, the "age" column shou... | codefeedback |
Implement the bubble sort algorithm to sort an array of numbers in descending order in-place. The input array should contain at most 100,000 elements and each element will be a positive integer less than or equal to 10^6. The algorithm should have a time complexity of O(n^2), where n is the number of elements in the in... | codefeedback |
Implement the bubble sort algorithm to sort an array of integers in Java.
arr = [5, 8, 2, 7, 1, 9, 3, 6, 4]
Your task is to sort the array in ascending order using the bubble sort algorithm. The bubble sort algorithm works by repeatedly swapping adjacent elements if they are in the wrong order. This process is repeat... | codefeedback |
Create a stacked bar chart on the webpage to display the data, where each bar represents a category and the height of each segment within the bar represents the value of a sub-category. The chart should also include axis labels, a title, and a legend indicating the sub-categories. The data should be retrieved from mult... | codefeedback |
Given two sorted arrays nums1 and nums2, combine their elements into a single array that is sorted. However, the combined array should not contain any duplicate elements. If there are duplicate elements in either of the input arrays, they should only appear once in the combined array.
Example:
nums1 = [1, 1, 2, 3, 4, ... | codefeedback |
Create a function to search a given string for the first vowel, while ignoring any vowels that are immediately followed by a consonant. The function should also return the index position of the vowel in the string.
Additionally, modify the function to handle multiple occurrences of vowels and return the index position... | codefeedback |
Given two unsorted arrays, merge them in a sorted form without using any extra space. The length of each array will not exceed 10^5. The elements in each array will be integers ranging from -10^5 to 10^5. | codefeedback |
Write a SQL query to print out the names and ages of employees in the Employees table who are older than 25, sorted in descending order of age.
Employees table is defined as: (employee_id int, first_name varchar(255), last_name varchar(255), age int).
In addition to the above requirement, add the following:
1. Exclu... | codefeedback |
Write a Java method named "reverseString" that takes in a string variable "str" as a parameter and returns the reverse of the input string. The method should handle both uppercase and lowercase characters. The returned string should have the first letter capitalized and the rest of the letters in lowercase. The input s... | codefeedback |
Construct a SQL query to find all the books with a price over £10 and written by authors whose names start with the letter "J". Additionally, the query should sort the results in descending order based on the book's publication date and only include books that were published within the last year. | codefeedback |
What is the most efficient way to store user input in JavaScript when the input consists of multiple fields with different data types and the input needs to be validated and sanitized before storage? Provide a solution that has a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Write a Python program to capture the entered text in an input box and validate that it meets the following criteria:
- The text must contain at least one uppercase letter and one lowercase letter
- The text must include at least one special character (!, @, #, $, %, &, or *)
- The text must include at least one digit ... | codefeedback |
Suggest a recursive method in JavaScript for finding the maximum of two numbers, ensuring that the method does not use any built-in mathematical functions or operators. Additionally, the method should have a time complexity of O(log(n)) and should not use any additional data structures or variables. | codefeedback |
Write a recursive algorithm in C++ for linear search, where the search must be performed on a sorted array in ascending order. The algorithm should return the index of the first occurrence of the target element, or -1 if the target element is not found. You are not allowed to use any loop constructs in your implementat... | codefeedback |
Write a function to determine if a given string is a valid English word or not, considering the following additional requirements:
- The function should have a time complexity of O(n), where n is the length of the input string.
- The function should use a Trie data structure to efficiently store and retrieve words.
- T... | codefeedback |
Find the number of distinct combinations of a given length from the characters in a given string, considering that each character can only be used once in each combination. The length of the string will not exceed 10^5 characters. The output should be modulo 10^9+7. | codefeedback |
Create a program to find the nth element of the Lucas sequence, where the Lucas sequence is defined as follows:
- The first two numbers in the sequence are 2 and 1.
- Each subsequent number in the sequence is the sum of the two preceding ones.
- The program should handle large values of n, up to 10^6. | codefeedback |
Calculate the Fibonacci sequence up to the n-th number where n is provided as an argument. The solution must have a time complexity of O(log n) and a space complexity of O(1). Additionally, you are not allowed to use recursion or iteration to solve this problem. | codefeedback |
Find the first non-repeating character in a string.
string: "aabbccdd"
## Additional Requirements ##
- The solution should have a time complexity of O(n).
- You are not allowed to use any additional data structures.
- Your solution should be case-sensitive.
## Reasoning Steps ##
1. Create a variable called `result` a... | codefeedback |
Write a ReactJS code to render the following DOM structure with dynamic data.
<div class="container">
<h1>Welcome, {name}!</h1>
<div>
<h2>I'm a {appType} App</h2>
<p>{description}</p>
<button onClick={handleClick}>Click Me</button>
</div>
</div>
Additional requirements:
1. The name should be a prop ... | codefeedback |
Create a program in Python for converting a given list of Fahrenheit temperatures to Celsius. The program should handle edge cases such as invalid input, such as non-numeric inputs or inputs that are not within the valid temperature range of -459.67 to 10000.0 degrees Fahrenheit. The program should also provide an opti... | codefeedback |
Read the following text and use a regular expression to extract email addresses.
Please contact john@example.com and lisa@mailcom for more information.
#Additional Instructions#
1. In addition to the original task of extracting email addresses, now also extract any phone numbers present in the text.
2. Modify the regu... | codefeedback |
Generate a program in Java that reads two strings and checks if the strings are equal. The program should also check if the strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. In addition, the program should count the number of occurrences of e... | codefeedback |
Get a random number between 1 and 1000 using C++ without using any built-in random functions or libraries. | codefeedback |
Generate a C# code for searching an element in a sorted array of integers using binary search algorithm. The code should handle cases where the array contains duplicate elements and return the index of the first occurrence of the target element. The search function should have a time complexity of O(log n) and should b... | codefeedback |
Use TensorFlow to build a deep learning model for predicting the future price of a given stock using a time series dataset with multiple features, such as volume, moving averages, and technical indicators. Additionally, incorporate a custom loss function that penalizes false negatives more than false positives in order... | codefeedback |
How would you write a query in SQL to return the names of all customers who have purchased over $100 in the last month, but excluding customers who have made more than 10 purchases in the last week and have also made a purchase in the last 24 hours? | codefeedback |
Write a React component for a form to allow users to submit a message. The form should include the following additional requirements:
- Users must enter a minimum of 20 characters in the message field.
- The form should include a character counter that displays the remaining characters allowed and highlights the counte... | codefeedback |
Create an algorithm in Java for the maximum subarray problem, with the added constraints that the subarray must contain at least one negative number, and the time complexity of the algorithm should be O(n).
#Revised Test#
You are given an array of integers. Write a Java algorithm to find the maximum sum of a subarray... | codefeedback |
Given two numbers N and M, write a program to find the number of numbers from 1 to N where the sum of their digits is divisible by M and the number itself is also divisible by M.
N = 100, M = 5 | codefeedback |
Write a program that takes a string of HTML code as input and identifies all the instances of nested div elements with a specific class attribute. Provide the starting and ending indices of each instance of the nested div elements in the string. | codefeedback |
Please identify and correct the error in the following code:
```python
def find_missing_number(nums):
for i in range(1, len(nums)+2):
if i not in nums:
return i
```
Propose a solution that has a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Create a secure RESTful web service for sending a daily email reminder to multiple recipients, where each email should be personalized with dynamic content and attachments based on individual recipient preferences. Additionally, the service should allow users to schedule the time of day for the reminder email to be sen... | codefeedback |
Create a SQL query to output the names of all the customers in the orders table, who have made at least 3 orders and have spent a total amount greater than $500, sorted in descending order of the total amount they have spent on orders. | codefeedback |
Explain the specific steps involved in implementing the Bellman-Ford algorithm for finding the shortest path in a weighted graph and how it differs from Dijkstra's algorithm. | codefeedback |
Write a Java program to find all prime numbers within a given range and store them in an array. The program should then display the prime numbers in descending order. | codefeedback |
Write a JavaScript program to check whether a particular character is present in a given string or not. The program should also count the number of occurrences of that character in the string. The program should be optimized to have a time complexity of O(n) and a space complexity of O(1).
String: 'Hello World!'
Char... | codefeedback |
Compare two strings and return 0 if they are identical, 1 if string a is lexicographically greater than b, or -1 if string b is lexicographically greater than a. Consider case-sensitivity while comparing the strings.
Strings:
a = "Hello World"
b = "hello world"
Additional Requirements:
- Implement the comparison algo... | codefeedback |
## New Test ##
Write a function called `reverse_name` that takes a string as a parameter and returns its reverse counterpart. The function should remove any whitespace characters at the beginning and end of the name before reversing it. Additionally, the function should capitalize the first letter of the reversed name.... | codefeedback |
Given a sentence, find the first verb in the sentence. The sentence may contain multiple clauses separated by punctuation marks such as commas, semicolons, or colons. Additionally, the verb may be in any tense (past, present, future) and can be in any form (base form, gerund, participle). The sentence may also contain ... | codefeedback |
Write a function to print out the triangle pattern as shown in the example.
The number of rows in the triangle should be equal to the given height.
The pattern should be printed in the following format:
1
232
34543
4567654
The numbers in each row should follow a specific pattern. In each row, the first and last numbe... | codefeedback |
Write a function that takes a list of strings and returns a list of words made up of the same letters, where each word contains at least 3 letters and each word should be in alphabetical order. Additionally, the output list should be sorted in descending order based on the length of the words.
word_list = ["aaa", "cab"... | codefeedback |
Increase the difficulty of the given programming test question by adding the following requirements:
1. Modify the "Account" class to include an additional attribute:
- Account opening date (datetime)
It should have methods to:
- Calculate and return the interest earned on the account balance
2. Modify the ... | codefeedback |
Edit an existing Python script to read a 3D array of size 1000 x 1000 x 1000 and calculate the sum of all its elements. | codefeedback |
Generate a random 5-digit number without using any in-built methods, and ensure that the number does not contain any repeating digits. | codefeedback |
Using the list of numbers, create a function to sort the list into ascending order. However, you are not allowed to use any built-in sorting functions or libraries. You must implement the sorting algorithm yourself.
numbers = [6, 4, 3, 2, 8]
#Rewritten Test with Increased Difficulty#
Using the list of numbers, creat... | codefeedback |
Using the data provided, create a function to calculate the mean value of the elements inside the dictionary. However, the function should only consider the elements with keys that start with a vowel (a, e, i, o, u). Additionally, the function should handle cases where the dictionary may contain nested dictionaries as ... | codefeedback |
Write a C++ function which allows the user to input two strings and prints the longest string. Additionally, the function should remove any duplicate characters from the longest string before printing it.
Time Complexity Requirement: O(n^2)
Space Complexity Requirement: O(n)
Example:
Input:
String 1: "programming"
St... | codefeedback |
Please write a program that implements a genetic algorithm for optimizing the weights of a feedforward neural network with multiple hidden layers. The program should include the following steps:
1. Initialize a population of potential solutions, where each solution represents a set of weights for the neural network. T... | codefeedback |
Provide a syntax for an if-else statement in Javascript, ensuring that the if condition checks for the presence of a specific element in an array and the else condition performs a mathematical operation on a variable, taking into account the current time. Additionally, include a try-catch block to handle any potential ... | codefeedback |
Design a method which takes in two sorted arrays of integers, `arr1` and `arr2`, of size `n` and `m` respectively. The method should return a new sorted array of size `n + m`.
The method should handle the following cases:
1. If either `arr1` or `arr2` is empty, the method should return the non-empty array as the resu... | codefeedback |
Suggest a sorting algorithm which takes minimal time to execute and provide the code for its implementation. Additionally, include a common error that could occur during the implementation of the algorithm and explain how to fix it.
#Difficulty Increased Test# | codefeedback |
Given a string, what is the most efficient algorithm to reverse the characters in it without using any built-in reverse functions or extra memory? Provide a piece of erroneous code that attempts to solve the problem, but does not correctly reverse the string. | codefeedback |
Create a class in Python for a student which should include the following fields: first name, last name, age, grade, a list of subjects, and a list of extracurricular activities.
The class should have the following methods:
1. A method to calculate the average grade of the student across all subjects.
2. A method to ... | codefeedback |
Write a code to find the longest common prefix among a given set of strings. The code should have a time complexity of O(n * m), where n is the number of strings in the set and m is the average length of the strings.
Additionally, handle the case where the given set of strings is empty and return an appropriate result... | codefeedback |
Write a program that takes in a string of code written in a specific programming language and identifies all the syntax errors, including missing semicolons, mismatched parentheses, and invalid variable names. Additionally, the program should provide suggestions on how to fix the errors and should be able to handle com... | codefeedback |
Write a code that takes the input of two strings, and returns the longest common substring in them. The code should also handle the case when there are multiple longest common substrings and return all of them. Additionally, the code should consider substrings that are palindromes as the longest common substrings. | codefeedback |
What are some popular libraries used in data science and machine learning for performing statistical analysis, data manipulation, and building predictive models? Please provide a brief explanation of each library and its main functionalities. Additionally, discuss the advantages and disadvantages of using each library ... | codefeedback |
Create a function that takes in two matrices as parameters, where the first matrix is a square matrix and the second matrix is an identity matrix of the same size. Additionally, the function should only allow matrices with dimensions between 2 and 10 (inclusive). The function should return the result of adding the two ... | codefeedback |
Explain the key differences between Python 2 and Python 3 in terms of syntax, and provide examples to illustrate each difference. Additionally, explain the differences in their approach to handling Unicode characters and how it affects string manipulation in the two versions. | codefeedback |
Create a Java program that takes input from a user and prints it out in reverse order. The program should also calculate and display the number of vowels in the input. Additionally, the program should implement the functionality to check if the input is a palindrome. A palindrome is a word, phrase, number, or other seq... | codefeedback |
Create a CSS style for the text within the tag <p> to be blue and italicized, with a font size of 16 pixels, a line height of 1.5, and a letter spacing of 1 pixel. The style should only apply to paragraphs with a class of "content" and should also include a text shadow of 2 pixels in both the horizontal and vertical di... | codefeedback |
Improve the following code by implementing a more efficient algorithm that sorts the positive elements in the array in descending order. Additionally, ensure that the sorted elements are unique and do not contain any duplicates.
def FunctionA(arr):
output = []
for elem in arr:
if elem > 0 and not elem ... | codefeedback |
Construct a while loop to add all prime odd integers from 1 to 100, excluding multiples of 5. | codefeedback |
Place the missing code in the following Java program to print "Hello World!".
- The program must use a method called "printMessage" to print the message.
- The message should be printed in reverse order, starting from the exclamation mark.
- The program should only use a single line of code inside the "main" method to ... | codefeedback |
Write an SQL query to find the country with the highest population density (population divided by land area) from the table of countries. Display the country name, population density, and land area. | codefeedback |
How can you create a string of all random characters of length 10 in Python, without using any built-in random functions or libraries, and with a time complexity of O(n)? | codefeedback |
Write a JavaScript function that takes in a positive integer as a parameter and prints the following pattern:
- The pattern should consist of a diamond shape made up of asterisks (*).
- The diamond should have a height equal to the given integer.
- The diamond should be horizontally and vertically centered.
- The diamo... | codefeedback |
Implement a recursive method to find the sum of all even numbers from 1 to n. The method should take an integer n as its argument. Additionally, the method should only use constant space complexity. The time complexity should be O(n). | codefeedback |
Create a PHP script to add a given user to a database, ensuring that the username is unique and contains at least 8 characters, and the password is at least 10 characters long, contains at least one uppercase letter, one lowercase letter, one number, and one special character. Additionally, the password should not cont... | codefeedback |
Implement a method in JavaScript to concatenate two strings together, but the result string should only contain the characters that appear in both input strings. Additionally, the method should return the resulting string sorted in ascending order of character ASCII values. | codefeedback |
Suggest a regular expression pattern that identifies 4 consecutive prime numbers. | codefeedback |
Write a SQL stored procedure to find all students enrolled in a specific course, ordered by their names in descending order. Additionally, the stored procedure should return the total number of courses each student is enrolled in.
Table: courses
Columns: Id (int), Name (string)
Table: students
Columns: Id (int), ... | codefeedback |
Write a Kotlin class to represent a book. It should contain the title, author name, year of publication, ISBN, and a list of genres that the book belongs to. The ISBN should be a 10-digit or 13-digit number. The title should be between 5 and 50 characters long. The author name should consist of only letters and should ... | codefeedback |
Implement the Sieve of Eratosthenes algorithm to efficiently find all prime numbers up to a given limit.
You are given a function signature:
```python
def sieve_of_eratosthenes(limit: int) -> List[int]:
pass
```
The function takes an integer `limit` as input and returns a list of all prime numbers up to the given... | codefeedback |
Create a dockerfile to deploy a complex Python web application that uses multiple services and external dependencies. The application should be scalable, fault-tolerant, and utilize microservices architecture. The dockerfile should include configuration for load balancing, caching, and database replication. Ensure the ... | codefeedback |
Reverse a given string using a recursive function in Python, without using any built-in string manipulation functions or data structures, and the function should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Write a function that takes a string as input and checks if it is a valid IPv4 address. An IPv4 address consists of four numbers (each ranging from 0 to 255) separated by periods. The function should return True if the input string is a valid IPv4 address and False otherwise. Additionally, the function should also chec... | codefeedback |
Create a Java program that takes in a String and returns a String with the letters of the original String reversed. However, your program should not use any built-in reverse methods or functions, and should have a time complexity of O(n) and a space complexity of O(1).
string = "Hello"
#Example Output#
olleH | codefeedback |
Write a JavaScript program to remove all the occurrences of a specified character from a string, while also counting the number of times the character appears in the string. The program should ignore the case sensitivity of the character. The input string should not contain any special characters or numbers. The progra... | codefeedback |
Use the MySQL CREATE command to create a table of employees containing an employee ID, name, email address, and phone number. The employee ID should be a primary key and auto-increment. The name should be limited to 50 characters and should not be null. The email address should be unique and should be in the format of ... | codefeedback |
Write a SQL query to select the first and last name of all employees that are located in New York, have a salary greater than $100,000, and have worked in the company for at least 5 years. | codefeedback |
Re-write the code in the given input to calculate the nth Fibonacci number using an iterative approach, with a time complexity of O(log n).
def fibonacci(n):
if n <= 1:
return n
fib_matrix = [[1, 1], [1, 0]]
power_matrix(fib_matrix, n-1)
return fib_matrix[0][0]
def power_matrix(matrix, n):
... | codefeedback |
Given two strings s1 and s2, write a function to return a new string containing the characters present only in s1, while ignoring any duplicates and case sensitivity. The returned string should be sorted in ascending order and should only contain alphabetic characters.
s1 = "AbCdeF"
s2 = "fghiJK" | codefeedback |
Create a function in Python that takes two parameters, start and end, and returns the sum of the squares of all numbers between them. If the start parameter is greater than the end parameter, return an error message stating that the start parameter should be less than the end parameter.
In addition, if the start param... | codefeedback |
Create a program in Python to return the first n elements from an array. However, the program should not use any built-in Python functions or methods such as slice or append to solve the problem. Instead, you should implement your own algorithm to extract the first n elements from the array. Additionally, the program s... | codefeedback |
Implement a function in Python that calculates the Damerau-Levenshtein Distance of two strings with a time complexity of O(m*n), where m is the length of str1 and n is the length of str2.
The Damerau-Levenshtein Distance allows for four types of operations: insertion, deletion, substitution, and transposition. A tran... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.